Class SchemaJsonConverter
- Namespace
- DatabentoDotNet.Historical.Json
- Assembly
- DatabentoDotNet.Historical.dll
Reads and writes Schema as the codec's wire string, in both the value and the property-name position.
public sealed class SchemaJsonConverter : JsonConverter<Schema>
- Inheritance
-
SchemaJsonConverter
- Inherited Members
Remarks
The property-name half is the point. Two metadata.* responses are JSON objects
keyed by schema — list_unit_prices' unit_prices (metadata.rs:274) and
get_dataset_range' schema (metadata.rs:317) — and
System.Text.Json's built-in enum key handling matches the C# member name, not the
wire string. So {"ohlcv-1s":…}, which is what the API sends, fails without this, while
{"Ohlcv1S":…}, which it never sends, succeeds. A test written from the C# names would
pass against a converter that does not work.
One converter covers List<Schema>, both keyed dictionaries, and any future field,
because JsonConverter<T> dispatches the key position to
ReadAsPropertyName(ref Utf8JsonReader, Type, JsonSerializerOptions) separately from Read(ref Utf8JsonReader, Type, JsonSerializerOptions).
An unrecognised schema throws, rather than yielding default: the issue's Definition of
done requires that "a schema the codec cannot name must be an error at the boundary, not an
unmapped enum value that reaches a caller as 0" — and 0 is
Mbo, a perfectly ordinary schema, so a silent fallback would be
indistinguishable from real data.
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to type Schema.
public override Schema Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Returns
- Schema
The converted value.
ReadAsPropertyName(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads a dictionary key from a JSON property name.
public override Schema ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe Utf8JsonReader to read from.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsThe options to use when reading the value.
Returns
- Schema
The value that was converted.
Write(Utf8JsonWriter, Schema, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, Schema value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write to.
valueSchemaThe value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
WriteAsPropertyName(Utf8JsonWriter, Schema, JsonSerializerOptions)
Writes a dictionary key as a JSON property name.
public override void WriteAsPropertyName(Utf8JsonWriter writer, Schema value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe Utf8JsonWriter to write to.
valueSchemaThe value to convert. The value of HandleNull determines if the converter handles null values.
optionsJsonSerializerOptionsThe options to use when writing the value.