Skip to main content

Class AnyEntityIdJsonConverter

Namespace: AdCodicem.ValueObjects.Identifiers
Assembly: AdCodicem.ValueObjects.Identifiers.dll

Moves an across a JSON boundary as the bare identifier text.

public sealed class AnyEntityIdJsonConverter : JsonConverter<AnyEntityId>

Inheritance

objectJsonConverterJsonConverter<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

AnyEntityId

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 to read from.

typeToConvert Type

The type to convert.

options JsonSerializerOptions

The options to use when reading the value.

Returns

AnyEntityId

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 to write to.

value AnyEntityId

The value to convert. The value of determines if the converter handles null values.

options JsonSerializerOptions

The options to use when writing the value.