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
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn 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
writerUtf8JsonWriterThe writer to write to.
valueMailAddressThe value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.