ExchangeRateJsonConverter Class
Definition
- Assembly
- Bodu.Financial.Serialization.Json.dll
- Package
- Bodu.Financial.Serialization.Json 1.0.0
Converts an ExchangeRate observation to and from JSON using the policy supplied at construction.
public sealed class ExchangeRateJsonConverter : JsonConverter<ExchangeRate>
- Inheritance
-
ExchangeRateJsonConverter
- Inherited Members
- Extension Methods
Remarks
Shape vocabulary:
-
Strict emits the full canonical object
{ "from", "to", "date", "rate", "provider", "isInverted" }in declaration order and rejects malformed inputs (non-string ISO codes, non-numeric rate, missing fields, duplicate fields, currency-mismatch shape). - Lenient shares the Strict shape but normalises lowercase ISO codes to uppercase and trims surrounding whitespace before validation. Intended for ingesting external feeds.
-
Compact emits a smaller object that combines the currencies into a single
"pair": "FROM/TO"property, dropsisInvertedwhen it is false, and uses ISO date string fordate. Reads accept both the canonical and compact shapes (presence of"pair"or"from"/"to"selects the shape).
Constructors
ExchangeRateJsonConverter()
Initializes a new instance of the ExchangeRateJsonConverter class configured for the Strict shape.
public ExchangeRateJsonConverter()
ExchangeRateJsonConverter(FinancialJsonPolicy)
Initializes a new instance of the ExchangeRateJsonConverter class configured for the supplied
policy.
public ExchangeRateJsonConverter(FinancialJsonPolicy policy)
Parameters
policyFinancialJsonPolicyThe serialization policy.
Exceptions
- ArgumentOutOfRangeException
policyis not a defined FinancialJsonPolicy value.
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to type ExchangeRate.
public override ExchangeRate Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Returns
- ExchangeRate
The converted value.
Write(Utf8JsonWriter, ExchangeRate, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, ExchangeRate value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write to.
valueExchangeRateThe value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |