BigDecimalJsonConverter Class
Definition
- Assembly
- Bodu.Numerics.Serialization.Json.dll
- Package
- Bodu.Numerics.Serialization.Json 1.0.0
Converts a BigDecimal to and from JSON using the policy supplied at construction.
public sealed class BigDecimalJsonConverter : JsonConverter<BigDecimal>
- Inheritance
-
BigDecimalJsonConverter
- Inherited Members
- Extension Methods
Remarks
The converter shape is selected by NumericsJsonPolicy:
-
Strict - canonical object form
{ "unscaledValue": 12340, "scale": 3 }. The unscaled value is written as a raw JSON number and may be read from a number or a numeric string, so an arbitrary-magnitude value round-trips without precision loss. - Lenient - the same object shape, and additionally a top-level JSON string is accepted and routed through the compact parser.
-
Compact - the plain decimal string
"12.340". Because JSON numbers can lose precision in some consumers, the value is written as a string rather than a bare number.
Constructors
BigDecimalJsonConverter()
Initializes a new instance of the BigDecimalJsonConverter class configured for the Strict shape.
public BigDecimalJsonConverter()
BigDecimalJsonConverter(NumericsJsonPolicy)
Initializes a new instance of the BigDecimalJsonConverter class configured for the supplied
policy.
public BigDecimalJsonConverter(NumericsJsonPolicy policy)
Parameters
policyNumericsJsonPolicyThe serialization policy.
Exceptions
- ArgumentOutOfRangeException
policyis not a defined NumericsJsonPolicy value.
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to type BigDecimal.
public override BigDecimal Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Returns
- BigDecimal
The converted value.
Write(Utf8JsonWriter, BigDecimal, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, BigDecimal value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write to.
valueBigDecimalThe value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |