Switch PubKeyJsonConverter from 'JsonConverter' to 'JsonConverter<T>'
MODIFY
WalletWasabi/JsonConverters/PubKeyJsonConverter.cs
WalletWasabi/JsonConverters/PubKeyJsonConverter.cs
@@ -3,24 +3,18 @@ using Newtonsoft.Json;
namespace WalletWasabi.JsonConverters;
-public class PubKeyJsonConverter : JsonConverter
+public class PubKeyJsonConverter : JsonConverter<PubKey>
{
/// <inheritdoc />
- public override bool CanConvert(Type objectType)
+ public override PubKey? ReadJson(JsonReader reader, Type objectType, PubKey? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
- return objectType == typeof(PubKey);
+ return new PubKey(((string?)reader.Value)?.Trim());
}
/// <inheritdoc />
- public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+ public override void WriteJson(JsonWriter writer, PubKey? value, JsonSerializer serializer)
{
- return new PubKey(((string)reader.Value).Trim());
- }
-
- /// <inheritdoc />
- public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
- {
- var pubKey = (PubKey)value;
- writer.WriteValue(pubKey.ToHex());
+ var pubKeyHex = value?.ToHex() ?? throw new ArgumentNullException(nameof(value));
+ writer.WriteValue(pubKeyHex);
}
}

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