Switch WitScriptJsonConverter from 'JsonConverter' to 'JsonConverter<T>'
MODIFY
WalletWasabi/WabiSabi/Models/Serialization/OwnershipProofJsonConverter.cs
WalletWasabi/WabiSabi/Models/Serialization/OwnershipProofJsonConverter.cs
@@ -4,22 +4,22 @@ using WalletWasabi.Crypto;
namespace WalletWasabi.WabiSabi.Models.Serialization;
-public class OwnershipProofJsonConverter : JsonConverter
+public class OwnershipProofJsonConverter : JsonConverter<OwnershipProof>
{
- public override bool CanConvert(Type objectType)
+ /// <inheritdoc />
+ public override OwnershipProof? ReadJson(JsonReader reader, Type objectType, OwnershipProof? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
- return objectType == typeof(OwnershipProof);
- }
-
- public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+ if (reader.Value is string serialized)
{
- var value = (string)reader.Value;
- return OwnershipProof.FromBytes(ByteHelpers.FromHex(value));
+ return OwnershipProof.FromBytes(ByteHelpers.FromHex(serialized));
+ }
+ throw new ArgumentException($"No valid serialized {nameof(OwnershipProof)} passed.");
}
- public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+ /// <inheritdoc />
+ public override void WriteJson(JsonWriter writer, OwnershipProof? value, JsonSerializer serializer)
{
- var bytes = ((OwnershipProof)value).ToBytes();
+ var bytes = value.ToBytes();
writer.WriteValue(ByteHelpers.ToHex(bytes));
}
}

MODIFY
WalletWasabi/WabiSabi/Models/Serialization/WitScriptJsonConverter.cs
WalletWasabi/WabiSabi/Models/Serialization/WitScriptJsonConverter.cs
@@ -3,22 +3,22 @@ using Newtonsoft.Json;
namespace WalletWasabi.WabiSabi.Models.Serialization;
-public class WitScriptJsonConverter : JsonConverter
+public class WitScriptJsonConverter : JsonConverter<WitScript>
{
- public override bool CanConvert(Type objectType)
+ /// <inheritdoc />
+ public override WitScript? ReadJson(JsonReader reader, Type objectType, WitScript? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
- return objectType == typeof(WitScript);
- }
-
- public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+ if (reader.Value is string serialized)
{
- var value = (string)reader.Value;
- return new WitScript(ByteHelpers.FromHex(value));
+ return new WitScript(ByteHelpers.FromHex(serialized));
+ }
+ throw new ArgumentException($"No valid serialized {nameof(WitScript)} passed.");
}
- public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+ /// <inheritdoc />
+ public override void WriteJson(JsonWriter writer, WitScript? value, JsonSerializer serializer)
{
- var bytes = ((WitScript)value).ToBytes();
+ var bytes = value?.ToBytes() ?? throw new ArgumentNullException(nameof(value));
writer.WriteValue(ByteHelpers.ToHex(bytes));
}
}

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