Class ReferenceCodeJsonConverter<T>
- Namespace
- DatabentoDotNet.Reference.Json
- Assembly
- DatabentoDotNet.Reference.dll
Reads and writes any IReferenceCode<TSelf> as its bare wire string.
public sealed class ReferenceCodeJsonConverter<T> : JsonConverter<T> where T : struct, IReferenceCode<T>
Type Parameters
TThe reference code type.
- Inheritance
-
ReferenceCodeJsonConverter<T>
- Inherited Members
Remarks
One converter for all ten types, closed over each of them by the
[JsonConverter(typeof(ReferenceCodeJsonConverter<Country>))] attribute the types
carry. That attribute is what the System.Text.Json source generator reads, so the ten
types are AOT-safe wherever a generated context includes a model that holds one — no reflection
fallback and no converter to register at a call site.
HandleNull is true, and it restates the framework default
rather than changing it. System.Text.Json derives the property from whether
default(T) is null, so a converter over a non-nullable struct — which is every one of
these — is handed the null token already, while a Nullable<T>
converter is not. Deleting the override leaves the whole suite green, the row-level tests that
read an explicit null into a Currency and a Frequency
included; that is how this was settled rather than reasoned about (#60).
The override is kept regardless, because reading a blank as no value is this file's decision rather than the framework's. A blank is a value the reference API genuinely sends, so null reads as default — no value, rather than an error — and it should stay this file's decision if that default ever moves. The nine closed-enum converters keep theirs for the same reason, and NullableFractionJsonConverter documents the other side of the same rule.
There is deliberately no property-name support, unlike
DatabentoDotNet.Historical.Json.SchemaJsonConverter. No reference response is keyed by one
of these types — CorporateAction's three open maps are keyed by field name — so
it would be untested surface. Add it with the first response that needs it.
Properties
HandleNull
Gets a value that indicates whether null should be passed to the converter on serialization, and whether Null should be passed on deserialization.
public override bool HandleNull { get; }
Property Value
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to type T.
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Returns
- T
The converted value.
Write(Utf8JsonWriter, T, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write to.
valueTThe value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.