Class PaymentTypeJsonConverter
- Namespace
- DatabentoDotNet.Reference.Json
- Assembly
- DatabentoDotNet.Reference.dll
Reads and writes PaymentType as its one-character wire code.
public sealed class PaymentTypeJsonConverter : JsonConverter<PaymentType>
- Inheritance
-
PaymentTypeJsonConverter
- Inherited Members
Remarks
An unrecognised code throws. That is the deliberate difference from the ten open code types ReferenceCodeJsonConverter<T> serves, and the argument for it is in ReferenceWireStrings: these alphabets were probed against the live server, so a code outside one means this library is stale rather than that the caller should be handed an opaque string. The offending code is in the message. So is a string whose length is not one, which is unrecognised for the same reason.
A blank is a legal payment type on the wire, and this converter still rejects it. The
PAYTYPE group lists a null-code entry and upstream models the field as
Option<PaymentType>, so a blank means "no value" — which a non-nullable
PaymentType field has no way to hold. A model field that may be blank is
PaymentType? carrying NullablePaymentTypeJsonConverter; this one is for a
field that may not.
Attached to the type by [JsonConverter], which is what the System.Text.Json
source generator reads — so PaymentType is AOT-safe wherever a generated context
holds a model carrying one, with no converter to register at a call site. If #53's
Internal/ReferenceJson.cs context turns out not to reach this converter through the
attribute, register it there.
Write(Utf8JsonWriter, PaymentType, JsonSerializerOptions) exists so the type is usable in a consumer's own serialization; nothing in
this library calls it, and upstream gives these enums a Serialize impl for the same
reason (enums.rs:65-72).
Properties
HandleNull
true, so a JSON null reaches Read(ref Utf8JsonReader, Type, JsonSerializerOptions) and is rejected
with a message rather than silently becoming default(PaymentType).
public override bool HandleNull { get; }
Property Value
Remarks
System.Text.Json already passes a null token to a value type's converter, so this restates the framework default rather than changing it. It is stated because the rejection below is the behaviour under test, and a default that quietly changed would turn it into an undefined enum value instead of an exception.
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to type PaymentType.
public override PaymentType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Returns
- PaymentType
The converted value.
Write(Utf8JsonWriter, PaymentType, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, PaymentType value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write to.
valuePaymentTypeThe value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.