Class DerivedTypeJsonConverter<T>
- Namespace
- Cratis.Serialization
- Assembly
- Cratis.Fundamentals.dll
Represents a JsonConverter<T> for converting types that are adorned with the DerivedTypeAttribute.
public class DerivedTypeJsonConverter<T> : JsonConverter<T>
Type Parameters
TThe interface the derived type implements to convert.
- Inheritance
-
DerivedTypeJsonConverter<T>
- Inherited Members
- Extension Methods
Remarks
Initializes a new instance of the DerivedTypeJsonConverter<T> class.
Constructors
DerivedTypeJsonConverter(IDerivedTypes)
Represents a JsonConverter<T> for converting types that are adorned with the DerivedTypeAttribute.
public DerivedTypeJsonConverter(IDerivedTypes derivedTypes)
Parameters
derivedTypesIDerivedTypesIDerivedTypes to use for discovering correct type.
Remarks
Initializes a new instance of the DerivedTypeJsonConverter<T> class.
Fields
DerivedTypeIdProperty
The property used in JSON to identify the derived type id.
public const string DerivedTypeIdProperty = "_derivedTypeId"
Field Value
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Derived type JSON deserialization uses types registered at startup that are preserved.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Derived type JSON deserialization uses types registered at startup that are safe for AOT.")]
public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReadertypeToConvertTypeoptionsJsonSerializerOptions
Returns
- T
Remarks
A missing derived type identifier returns the default value so payloads written without nested identifiers by earlier versions remain readable when replaying persisted events.
Write(Utf8JsonWriter, T, JsonSerializerOptions)
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Derived type JSON serialization uses types registered at startup that are preserved.")]
[UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Derived type JSON serialization accesses well-known type properties that are preserved.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Derived type JSON serialization uses types registered at startup that are safe for AOT.")]
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWritervalueToptionsJsonSerializerOptions
Remarks
Nested children and collections declared with a derived type family use their declared types to preserve type identifiers and the converter's naming rules. Other properties use runtime types.