Table of Contents

Class MaybePrimitiveJsonConverter<T>

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

JSON converter for Maybe<T> where T is an STJ-native primitive in the allowed list enforced by MaybePrimitiveJsonConverterFactory.

public sealed class MaybePrimitiveJsonConverter<T> : JsonConverter<Maybe<T>> where T : notnull

Type Parameters

T

One of: string, decimal, int, long, short, byte, double, float, bool, Guid, DateTime, DateTimeOffset.

Inheritance
MaybePrimitiveJsonConverter<T>
Inherited Members
Extension Methods

Remarks

  • JSON null → Maybe<T>.None (no error; absent or null are both "not provided").
  • Primitive JSON value → Maybe.From(T) using STJ's typed primitive reader.
  • Wrong JSON shape (e.g. number for a string field) throws the standard JsonException.
  • None writes as JSON null.

Reads and writes dispatch on the closed primitive allowed list via typed Utf8JsonReader / Utf8JsonWriter methods — no reflection, no JsonSerializer round-trip, no AOT/trim warnings.

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to type Trellis.Maybe.

public override Maybe<T> 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

Maybe<T>

The converted value.

Write(Utf8JsonWriter, Maybe<T>, JsonSerializerOptions)

Writes a specified value as JSON.

public override void Write(Utf8JsonWriter writer, Maybe<T> value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The writer to write to.

value Maybe<T>

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.