Switch GuidJsonConverter from 'JsonConverter' to 'JsonConverter<T>'
MODIFY
WalletWasabi/JsonConverters/GuidJsonConverter.cs
WalletWasabi/JsonConverters/GuidJsonConverter.cs
@@ -6,7 +6,7 @@ namespace WalletWasabi.JsonConverters;
/// JSON converter for <see cref="Guid"/>.
/// https://gist.github.com/ReubenBond/9416e7a4c528eab473fd
/// </summary>
-public class GuidJsonConverter : JsonConverter
+public class GuidJsonConverter : JsonConverter<Guid>
{
/// <summary>
/// Gets a value indicating whether this <see cref="T:Newtonsoft.Json.JsonConverter"/> can write JSON.
@@ -15,21 +15,6 @@ public class GuidJsonConverter : JsonConverter
/// </value>
public override bool CanWrite => true;
- /// <summary>
- /// Determines whether this instance can convert the specified object type.
- /// </summary>
- /// <param name="objectType">
- /// Kind of the object.
- /// </param>
- /// <returns>
- /// <see langword="true"/> if this instance can convert the specified object type; otherwise,
- /// .
- /// </returns>
- public override bool CanConvert(Type objectType)
- {
- return objectType.IsAssignableFrom(typeof(Guid)) || objectType.IsAssignableFrom(typeof(Guid?));
- }
-
/// <summary>
/// Writes the JSON representation of the object.
/// </summary>
@@ -42,16 +27,9 @@ public class GuidJsonConverter : JsonConverter
/// <param name="serializer">
/// The calling serializer.
/// </param>
- public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
- {
- if (value is null)
+ public override void WriteJson(JsonWriter writer, Guid value, JsonSerializer serializer)
{
- writer.WriteValue(default(string));
- }
- else if (value is Guid guid)
- {
- writer.WriteValue(guid.ToString("N"));
- }
+ writer.WriteValue(value.ToString("N"));
}
/// <summary>
@@ -72,10 +50,11 @@ public class GuidJsonConverter : JsonConverter
/// <returns>
/// The object value.
/// </returns>
- public override object ReadJson(
+ public override Guid ReadJson(
JsonReader reader,
Type objectType,
- object existingValue,
+ Guid existingValue,
+ bool hasExistingValue,
JsonSerializer serializer)
{
return reader.Value is string str ? Guid.Parse(str) : default;

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