Class InstantJsonConverter
- Namespace
- DatabentoDotNet.Historical.Json
- Assembly
- DatabentoDotNet.Historical.dll
Reads an Instant from the six timestamp spellings below — not every spelling the
historical API sends. ISO 8601 with a numeric offset (2023-06-14T10:00:00+05:00) throws
rather than being accepted; that is a deliberate divergence, not an oversight, because
rejecting it is better than upstream's own behaviour of silently discarding the offset it read.
public sealed class InstantJsonConverter : JsonConverter<Instant>
- Inheritance
-
InstantJsonConverter
- Inherited Members
Remarks
Six patterns, because no fewer will do. Upstream parses these in two branches: ISO 8601
as a zone-less PrimitiveDateTime that is then assumed UTC, falling back to a legacy
space-separated format with an optional .ffffff and an optional +HH:mm
(databento-rs/src/deserialize.rs:7-19). NodaTime splits that across more patterns than
the time crate needs, for two measured reasons:
ExtendedIso parses 2023-06-14T10:00:00Z but throws on
2023-06-14T10:00:00; ExtendedIso does exactly the
reverse. So the ISO branch alone needs both. And NodaTime patterns have no optional-section
syntax, so each of the legacy branch's four combinations of "subsecond or not" and "offset or
not" needs its own pattern.
The order is upstream's — ISO first, legacy second — though it does not affect the result: every pattern here is exact, and a value that matches one matches no other.
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.