Table of Contents

Class ScalarValueJsonConverterBase<TResult, TValue, TPrimitive>

Namespace
Trellis.Asp.Validation
Assembly
Trellis.Asp.dll

Base JSON converter for scalar value objects that collects validation errors instead of throwing exceptions during deserialization.

public abstract class ScalarValueJsonConverterBase<TResult, TValue, TPrimitive> : JsonConverter<TResult> where TValue : class, IScalarValue<TValue, TPrimitive> where TPrimitive : IComparable

Type Parameters

TResult

The result type of deserialization (e.g., TValue? or Maybe<TValue>).

TValue

The scalar value object type.

TPrimitive

The underlying primitive type.

Inheritance
JsonConverter<TResult>
ScalarValueJsonConverterBase<TResult, TValue, TPrimitive>
Derived
Inherited Members
Extension Methods

Properties

HandleNull

Tells System.Text.Json to call Read(ref Utf8JsonReader, Type, JsonSerializerOptions) even when the JSON token is null. Without this, the serializer bypasses the converter for null tokens on reference-type results, preventing OnNullToken(string) from firing.

public override bool HandleNull { get; }

Property Value

bool

Methods

GetDefaultFieldName()

Gets the default field name derived from the value object type name.

protected static string GetDefaultFieldName()

Returns

string

OnNullToken(string)

Returns the result when a JSON null token is read.

protected abstract TResult OnNullToken(string fieldName)

Parameters

fieldName string

The resolved field name for error reporting.

Returns

TResult

OnValidationFailure()

Returns the result when validation fails.

protected abstract TResult OnValidationFailure()

Returns

TResult

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to type T.

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "TPrimitive type parameter is preserved by JSON serialization infrastructure")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "JSON deserialization of primitive types is compatible with AOT")]
public override TResult 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

TResult

The converted value.

WrapSuccess(TValue)

Wraps a successfully validated value object into the result type.

protected abstract TResult WrapSuccess(TValue value)

Parameters

value TValue

Returns

TResult