Table of Contents

ExchangeRateJsonConverter Class

Definition

Namespace
Bodu.Financial.Serialization.Json
Assembly
Bodu.Financial.Serialization.Json.dll
Package
Bodu.Financial.Serialization.Json 1.0.0
Source
ExchangeRateJsonConverter.cs

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, drops isInverted when it is false, and uses ISO date string for date. 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

policy FinancialJsonPolicy

The serialization policy.

Exceptions

ArgumentOutOfRangeException

policy is 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

reader Utf8JsonReader

The reader.

typeToConvert Type

The type to convert.

options JsonSerializerOptions

An 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

writer Utf8JsonWriter

The writer to write to.

value ExchangeRate

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.

Applies to

ProductVersions
.NET8, 10