Switch HDFingerprintJsonConverter from 'JsonConverter' to 'JsonConverter<T>'
MODIFY
WalletWasabi/JsonConverters/HDFingerprintJsonConverter.cs
WalletWasabi/JsonConverters/HDFingerprintJsonConverter.cs
@@ -3,21 +3,15 @@ using Newtonsoft.Json;
namespace WalletWasabi.JsonConverters;
-public class HDFingerprintJsonConverter : JsonConverter
+public class HDFingerprintJsonConverter : JsonConverter<HDFingerprint>
{
/// <inheritdoc />
- public override bool CanConvert(Type objectType)
+ public override HDFingerprint ReadJson(JsonReader reader, Type objectType, HDFingerprint existingValue, bool hasExistingValue, JsonSerializer serializer)
{
- return objectType == typeof(HDFingerprint);
- }
-
- /// <inheritdoc />
- public override object? ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
- {
- var s = (string)reader.Value;
+ var s = (string?)reader.Value;
if (string.IsNullOrWhiteSpace(s))
{
- return null;
+ throw new ArgumentNullException(nameof(reader.Value));
}
var fp = new HDFingerprint(ByteHelpers.FromHex(s));
@@ -25,11 +19,8 @@ public class HDFingerprintJsonConverter : JsonConverter
}
/// <inheritdoc />
- public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+ public override void WriteJson(JsonWriter writer, HDFingerprint value, JsonSerializer serializer)
{
- var fp = (HDFingerprint)value;
-
- var s = fp.ToString();
- writer.WriteValue(s);
+ writer.WriteValue(value.ToString());
}
}

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