Class AnyEntityIdJsonConverter
Namespace: AdCodicem.ValueObjects.Identifiers
Assembly: AdCodicem.ValueObjects.Identifiers.dll
Moves an
public sealed class AnyEntityIdJsonConverter : JsonConverter<AnyEntityId>
Inheritance
object ← JsonConverter ← JsonConverter<AnyEntityId> ← AnyEntityIdJsonConverter
Inherited Members
JsonConverter<AnyEntityId>.CanConvert(Type), JsonConverter<AnyEntityId>.Read(ref Utf8JsonReader, Type, JsonSerializerOptions), JsonConverter<AnyEntityId>.ReadAsPropertyName(ref Utf8JsonReader, Type, JsonSerializerOptions), JsonConverter<AnyEntityId>.Write(Utf8JsonWriter, AnyEntityId, JsonSerializerOptions), JsonConverter<AnyEntityId>.WriteAsPropertyName(Utf8JsonWriter, AnyEntityId, JsonSerializerOptions), JsonConverter<AnyEntityId>.HandleNull, JsonConverter<AnyEntityId>.Type, JsonConverter.CanConvert(Type), JsonConverter.Type, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
Without this the serializer would reflect over the struct and write an object with a value, a prefix and a
type name — which is not what an identifier looks like anywhere else in this library, and is precisely the
wrong shape for the payloads this type exists to serve. Writing the text also makes the default OpenAPI
schema a plain string, which is the representation chosen over a oneOf across every registered
pattern: faithful, and unreadable past a handful of identifier types.
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to type
public override AnyEntityId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
reader Utf8JsonReader
The reader.
typeToConvert Type
The type to convert.
options JsonSerializerOptions
An object that specifies serialization options to use.
Returns
The converted value.
ReadAsPropertyName(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads a dictionary key from a JSON property name.
public override AnyEntityId ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
reader Utf8JsonReader
The
typeToConvert Type
The type to convert.
options JsonSerializerOptions
The options to use when reading the value.
Returns
The value that was converted.
Write(Utf8JsonWriter, AnyEntityId, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, AnyEntityId value, JsonSerializerOptions options)
Parameters
writer Utf8JsonWriter
The writer to write to.
value AnyEntityId
The value to convert to JSON.
options JsonSerializerOptions
An object that specifies serialization options to use.
WriteAsPropertyName(Utf8JsonWriter, AnyEntityId, JsonSerializerOptions)
Writes a dictionary key as a JSON property name.
public override void WriteAsPropertyName(Utf8JsonWriter writer, AnyEntityId value, JsonSerializerOptions options)
Parameters
writer Utf8JsonWriter
The
value AnyEntityId
The value to convert. The value of
options JsonSerializerOptions
The options to use when writing the value.