Class InstantJsonConverter
- Namespace
- MassiveDotNet.Serialization
- Assembly
- MassiveDotNet.dll
Reads and writes a moment on the global timeline in the RFC 3339 form the Massive API uses for
format: date-time fields, such as 2024-06-24T18:33:53Z.
public sealed class InstantJsonConverter : JsonConverter<Instant>
- Inheritance
-
InstantJsonConverter
- Inherited Members
Remarks
Parses straight from the reader's UTF-8 bytes: no intermediate string, and none of the
ParseResult allocation NodaTime's pattern API incurs per value. A thousand-article news
page would otherwise allocate a thousand objects that are discarded immediately.
Accepts YYYY-MM-DDTHH:MM:SS, an optional fraction of one to nine digits, then Z
or a numeric ±HH:MM offset. The T and Z designators may be lowercase, as
RFC 3339 permits. Anything else is a JsonException, naming the value unless it is
longer than any spelling of a timestamp could be, in which case it reports only that (D41).
Registered once on the generated REST serialization context, so every Instant
property on every model uses it without a per-property attribute. A nullable
Instant? property resolves to this converter through the serializer's own nullable
wrapper.
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to type Instant.
public override Instant Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Returns
- Instant
The converted value.
Write(Utf8JsonWriter, Instant, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, Instant value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write to.
valueInstantThe value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.