Skip to main content

Class ValueObjectJsonConverter<TSelf, TValue>

Namespace: AdCodicem.ValueObjects.Json
Assembly: AdCodicem.ValueObjects.Json.dll

Serializes a value object as its bare underlying value, delegating the underlying value to System.Text.Json itself.

[RequiresUnreferencedCode("Delegating the underlying value to the serializer needs its metadata, which trimming may remove. Generated value objects carry their own converter and do not go through this one.")]
[RequiresDynamicCode("Delegating the underlying value to the serializer may need run-time code generation. Generated value objects carry their own converter and do not go through this one.")]
public sealed class ValueObjectJsonConverter<TSelf, TValue> : JsonConverter<TSelf> where TSelf : struct, IValueObject<TSelf, TValue>

Type Parameters

TSelf

Value object type.

TValue

Underlying value type.

Inheritance

objectJsonConverterJsonConverter<TSelf>ValueObjectJsonConverter<TSelf, TValue>

Inherited Members

JsonConverter<TSelf>.CanConvert(Type), JsonConverter<TSelf>.Read(ref Utf8JsonReader, Type, JsonSerializerOptions), JsonConverter<TSelf>.ReadAsPropertyName(ref Utf8JsonReader, Type, JsonSerializerOptions), JsonConverter<TSelf>.Write(Utf8JsonWriter, TSelf, JsonSerializerOptions), JsonConverter<TSelf>.WriteAsPropertyName(Utf8JsonWriter, TSelf, JsonSerializerOptions), JsonConverter<TSelf>.HandleNull, JsonConverter<TSelf>.Type, JsonConverter.CanConvert(Type), JsonConverter.Type, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks

This is the general-purpose converter, used for value objects written by hand. A generated value object carries its own converter, which writes the value directly instead of going back through the serializer, and is the one the factory hands out whenever it is available.

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to type T.

public override TSelf 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

TSelf

The converted value.

ReadAsPropertyName(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads a dictionary key from a JSON property name.

public override TSelf 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

TSelf

The value that was converted.

Write(Utf8JsonWriter, TSelf, JsonSerializerOptions)

Writes a specified value as JSON.

public override void Write(Utf8JsonWriter writer, TSelf value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The writer to write to.

value TSelf

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.

WriteAsPropertyName(Utf8JsonWriter, TSelf, JsonSerializerOptions)

Writes a dictionary key as a JSON property name.

public override void WriteAsPropertyName(Utf8JsonWriter writer, TSelf value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The to write to.

value TSelf

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

options JsonSerializerOptions

The options to use when writing the value.