NumericsJsonSerializerOptionsExtensions Class
Definition
- Assembly
- Bodu.Numerics.Serialization.Json.dll
- Package
- Bodu.Numerics.Serialization.Json 1.0.0
Extension methods that register the Bodu.Numerics JSON converters on a JsonSerializerOptions,
picking a coherent shape for every shipped numeric type from a single NumericsJsonPolicy value.
public static class NumericsJsonSerializerOptionsExtensions
- Inheritance
-
NumericsJsonSerializerOptionsExtensions
- Inherited Members
Methods
AddNumericsJsonConverters(JsonSerializerOptions, NumericsJsonPolicy)
Registers the JSON converters for every serializable Bodu.Numerics value type on
options, configured for the supplied policy.
public static JsonSerializerOptions AddNumericsJsonConverters(this JsonSerializerOptions options, NumericsJsonPolicy policy = NumericsJsonPolicy.Strict)
Parameters
optionsJsonSerializerOptionsThe serializer options to extend.
policyNumericsJsonPolicyThe serialization policy applied to every registered converter. Defaults to Strict.
Returns
- JsonSerializerOptions
The same
optionsinstance, so calls can be chained inline.
Remarks
The core Bodu.Numerics types carry no [JsonConverter] attribute - the library is
serialization-agnostic - so this call is required for Fraction<T>, Interval<T>,
DiscreteInterval<T>, IntervalSet<T>, BigDecimal, and
Complex<T> to round-trip through their canonical shapes. The IntervalPair<T> and
DiscreteIntervalPair<T> result types are transient and are not serializable; convert them with
ToIntervalSet() and serialize the resulting IntervalSet<T> instead.
Use Strict for canonical persistence shapes,
Lenient for import workflows tolerant of "min"/"max" aliases and
compact-string fallbacks, and Compact for the single-string representations (
"3/4", "[1, 5)", "∅").
Exceptions
- ArgumentNullException
optionsis null.- ArgumentOutOfRangeException
policyis not a defined NumericsJsonPolicy value.- InvalidOperationException
optionshas already been used for serialization or deserialization, in which case Converters is read-only. Configure options before first use.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |