MoneyOfTCurrencyJsonConverter<TCurrency> Class
Definition
- Assembly
- Bodu.Financial.Serialization.Json.dll
- Package
- Bodu.Financial.Serialization.Json 1.0.0
Converts a Money<TCurrency> to and from JSON using the policy supplied at construction.
public sealed class MoneyOfTCurrencyJsonConverter<TCurrency> : JsonConverter<Money<TCurrency>> where TCurrency : ICurrency
Type Parameters
TCurrencyThe currency type identifier.
- Inheritance
-
JsonConverter<Money<TCurrency>>MoneyOfTCurrencyJsonConverter<TCurrency>
- Inherited Members
- Extension Methods
Remarks
The converter shape is selected by FinancialJsonPolicy:
-
Strict - canonical object form
{ "amount": 19.99, "currency": "USD" }; rejects duplicate properties and currency mismatches. - Lenient - same shape as Strict, with additional tolerance for lowercase currency codes and whitespace around the currency value.
-
Compact - string form
"19.99 USD"; reads accept either ISO-prefix or ISO-suffix arrangement and reuse TryParse(ReadOnlySpan<char>, IFormatProvider?, out Money<TCurrency>).
Constructors
MoneyOfTCurrencyJsonConverter()
Initializes a new instance of the MoneyOfTCurrencyJsonConverter<TCurrency> class configured for the Strict shape.
public MoneyOfTCurrencyJsonConverter()
MoneyOfTCurrencyJsonConverter(FinancialJsonPolicy)
Initializes a new instance of the MoneyOfTCurrencyJsonConverter<TCurrency> class configured for
the supplied policy.
public MoneyOfTCurrencyJsonConverter(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 Money.
public override Money<TCurrency> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Returns
- Money<TCurrency>
The converted value.
Write(Utf8JsonWriter, Money<TCurrency>, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, Money<TCurrency> value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write to.
valueMoney<TCurrency>The value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |