<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />

JsonConverter<T>

public abstract class JsonConverter<T> : JsonConverter
Converts an object to and from JSON.
using Newtonsoft.Json.Utilities; using System; using System.Globalization; using System.Runtime.CompilerServices; namespace Newtonsoft.Json { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public abstract class JsonConverter<[System.Runtime.CompilerServices.Nullable(2)] T> : JsonConverter { public sealed override void WriteJson(JsonWriter writer, [System.Runtime.CompilerServices.Nullable(2)] object value, JsonSerializer serializer) { if (!((value != null) ? (value is T) : ReflectionUtils.IsNullable(typeof(T)))) throw new JsonSerializationException("Converter cannot write specified value to JSON. {0} is required.".FormatWith(CultureInfo.InvariantCulture, typeof(T))); WriteJson(writer, (T)value, serializer); } public abstract void WriteJson(JsonWriter writer, [System.Runtime.CompilerServices.Nullable(2)] T value, JsonSerializer serializer); [return: System.Runtime.CompilerServices.Nullable(2)] public sealed override object ReadJson(JsonReader reader, Type objectType, [System.Runtime.CompilerServices.Nullable(2)] object existingValue, JsonSerializer serializer) { bool flag = existingValue == null; if (!flag && !(existingValue is T)) throw new JsonSerializationException("Converter cannot read JSON with the specified existing value. {0} is required.".FormatWith(CultureInfo.InvariantCulture, typeof(T))); return ReadJson(reader, objectType, flag ? default(T) : ((T)existingValue), !flag, serializer); } [return: System.Runtime.CompilerServices.Nullable(2)] public abstract T ReadJson(JsonReader reader, Type objectType, [System.Runtime.CompilerServices.Nullable(2)] T existingValue, bool hasExistingValue, JsonSerializer serializer); public sealed override bool CanConvert(Type objectType) { return typeof(T).IsAssignableFrom(objectType); } } }