Table of Contents

Class EmailJsonConverter

Namespace
Vonage.Common.Serialization
Assembly
Vonage.dll

Represents a custom converter from Email to Json.

public class EmailJsonConverter : JsonConverter<MailAddress>
Inheritance
EmailJsonConverter
Inherited Members

Examples

var options = new JsonSerializerOptions();
options.Converters.Add(new EmailJsonConverter());

// Serializes MailAddress to its string representation
var email = MailAddress.Parse("user@example.com").IfFailure(default(MailAddress));
string json = JsonSerializer.Serialize(email, options);
// Produces: "user@example.com"

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to type MailAddress.

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

MailAddress

The converted value.

Write(Utf8JsonWriter, MailAddress, JsonSerializerOptions)

Writes a specified value as JSON.

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

Parameters

writer Utf8JsonWriter

The writer to write to.

value MailAddress

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.