Table of Contents

Class NullableDateTimeOffsetConverter

Namespace
Mailtrap.Core.Converters
Assembly
Mailtrap.Abstractions.dll

JSON converter for nullable DateTimeOffset. Supports reading both ISO 8601 string format and Unix time in milliseconds. Writes only ISO 8601 string format. To write Unix time in milliseconds please use Mailtrap.Core.Converters.NullableDateTimeOffsetUnixMsConverter Empty or whitespace strings are treated as null.

public sealed class NullableDateTimeOffsetConverter : JsonConverter<DateTimeOffset?>
Inheritance
NullableDateTimeOffsetConverter
Inherited Members

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to type DateTimeOffset?.

public override DateTimeOffset? 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

DateTimeOffset?

The converted value.

Exceptions

JsonException

Thrown when the JSON value cannot be parsed as a valid DateTimeOffset.

Write(Utf8JsonWriter, DateTimeOffset?, JsonSerializerOptions)

Writes a specified value as JSON.

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

Parameters

writer Utf8JsonWriter

The writer to write to.

value DateTimeOffset?

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.