Table of Contents

NumericsJsonSerializerOptionsExtensions Class

Definition

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

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

options JsonSerializerOptions

The serializer options to extend.

policy NumericsJsonPolicy

The serialization policy applied to every registered converter. Defaults to Strict.

Returns

JsonSerializerOptions

The same options instance, 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

options is null.

ArgumentOutOfRangeException

policy is not a defined NumericsJsonPolicy value.

InvalidOperationException

options has already been used for serialization or deserialization, in which case Converters is read-only. Configure options before first use.

Applies to

ProductVersions
.NET8, 10