Table of Contents

Class MaybeJsonConverter<T>

Namespace
Vonage.Common.Serialization
Assembly
Vonage.dll

Represents a custom converter from Maybe to Json.

public class MaybeJsonConverter<T> : JsonConverter<Maybe<T>>

Type Parameters

T

The underlying type.

Inheritance
MaybeJsonConverter<T>
Derived
Inherited Members

Examples

var options = new JsonSerializerOptions();
options.Converters.Add(new MaybeJsonConverter<string>());

// A Some value serializes to its contained value
Maybe<string> name = "Alice";
string json = JsonSerializer.Serialize(name, options);
// Produces: "Alice"

// A None value serializes to nothing (skipped in object serialization)

Fields

Serializer

protected JsonSerializer Serializer

Field Value

JsonSerializer

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to type Vonage.Common.Monads.Maybe{`0}.

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.