Class DictionaryJsonConverter<TKey, TValue>
- Namespace
- Cratis.Json
- Assembly
- Cratis.Fundamentals.dll
Represents a JsonConverter for converting dictionaries to and from JSON.
public abstract class DictionaryJsonConverter<TKey, TValue> : JsonConverter<IDictionary<TKey, TValue>> where TKey : notnull
Type Parameters
TKeyKey of the dictionary.
TValueValue of the dictionary.
- Inheritance
-
JsonConverter<IDictionary<TKey, TValue>>DictionaryJsonConverter<TKey, TValue>
- Inherited Members
- Extension Methods
Constructors
DictionaryJsonConverter()
protected DictionaryJsonConverter()
Methods
GetKeyFromString(string)
Get the key instance from the string representation.
protected abstract TKey GetKeyFromString(string key)
Parameters
keystringString representation of the key.
Returns
- TKey
New key instance.
GetKeyString(TKey)
Get the string representation of the key.
protected virtual string GetKeyString(TKey key)
Parameters
keyTKeyKey to get from.
Returns
- string
String representation.
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Dictionary JSON deserialization uses well-known types that are preserved.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Dictionary JSON deserialization uses well-known types that are safe for AOT.")]
public override IDictionary<TKey, TValue>? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReadertypeToConvertTypeoptionsJsonSerializerOptions
Returns
- IDictionary<TKey, TValue>
Write(Utf8JsonWriter, IDictionary<TKey, TValue>, JsonSerializerOptions)
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Dictionary JSON serialization uses well-known types that are preserved.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Dictionary JSON serialization uses well-known types that are safe for AOT.")]
public override void Write(Utf8JsonWriter writer, IDictionary<TKey, TValue> value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWritervalueIDictionary<TKey, TValue>optionsJsonSerializerOptions