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
TThe underlying type.
- Inheritance
-
JsonConverter<Maybe<T>>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
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
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn 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
writerUtf8JsonWriterThe writer to write to.
valueMaybe<T>The value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.