Table of Contents

BigDecimalJsonConverter Class

Definition

Namespace
Bodu.Numerics.Serialization.Json
Assembly
Bodu.Numerics.Serialization.Json.dll
Package
Bodu.Numerics.Serialization.Json 1.0.0
Source
BigDecimalJsonConverter.cs

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

policy NumericsJsonPolicy

The serialization policy.

Exceptions

ArgumentOutOfRangeException

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

reader Utf8JsonReader

The reader.

typeToConvert Type

The type to convert.

options JsonSerializerOptions

An 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

writer Utf8JsonWriter

The writer to write to.

value BigDecimal

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.

Applies to

ProductVersions
.NET8, 10