Switch NetworkJsonConverter from 'JsonConverter' to 'JsonConverter<T>'
MODIFY
WalletWasabi/JsonConverters/NetworkJsonConverter.cs
WalletWasabi/JsonConverters/NetworkJsonConverter.cs
@@ -7,19 +7,13 @@ namespace WalletWasabi.JsonConverters;
/// Converter used to convert <see cref="Network"/> to and from JSON.
/// </summary>
/// <seealso cref="JsonConverter" />
-public class NetworkJsonConverter : JsonConverter
+public class NetworkJsonConverter : JsonConverter<Network>
{
/// <inheritdoc />
- public override bool CanConvert(Type objectType)
- {
- return objectType == typeof(Network);
- }
-
- /// <inheritdoc />
- public override object? ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+ public override Network? ReadJson(JsonReader reader, Type objectType, Network? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
// check additional strings that are not checked by GetNetwork
- string networkString = ((string)reader.Value).Trim();
+ var networkString = ((string?)reader.Value)?.Trim();
if ("regression".Equals(networkString, StringComparison.OrdinalIgnoreCase))
{
return Network.RegTest;
@@ -29,8 +23,9 @@ public class NetworkJsonConverter : JsonConverter
}
/// <inheritdoc />
- public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+ public override void WriteJson(JsonWriter writer, Network? value, JsonSerializer serializer)
{
- writer.WriteValue(((Network)value).ToString());
+ var network = value?.ToString() ?? throw new ArgumentNullException(nameof(value));
+ writer.WriteValue(network);
}
}

Switch NetworkJsonConverter from 'JsonConverter' to 'JsonConverter<T>'