Table of Contents

NumericsJsonPolicy Enum

Definition

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

Selects the JSON serialization shape and parsing strictness applied by the Bodu.Numerics JSON converters.

public enum NumericsJsonPolicy
Extension Methods

Fields

Strict = 0

Canonical JSON shape suitable for persistence and interchange data: Fraction<T> serializes as an object with "numerator" and "denominator" properties; Interval<T> serializes as an object with "lower", "upper", "lowerInclusive", and "upperInclusive" properties (or the single-property object { "empty": true } for an empty interval). Property names compare case-insensitively, duplicate properties are rejected, and unknown properties are ignored.

Lenient = 1

Same on-the-wire shape as Strict, with additional tolerance for import workflows: a top-level JSON string is accepted and routed through the compact parser as a fallback; for Interval<T> the "min" and "max" aliases are accepted for "lower" and "upper", and missing endpoint inclusion properties default to closed. Intended for spreadsheet and external-feed ingest. Not suitable as a canonical storage shape.

Compact = 2

Compact JSON shape: Fraction<T> serializes as a single JSON string of the form "<numerator>/<denominator>" (for example "3/4"); Interval<T> serializes as a JSON string in ISO 31-11 bracket notation (for example "[1, 5)") or as the empty-set glyph "∅". Reads delegate to the type's Parse / TryParse path.

Remarks

The policy is supplied either by constructing a converter directly (e.g. new FractionJsonConverter<int>(NumericsJsonPolicy.Compact)) or, more commonly, through AddNumericsJsonConverters(JsonSerializerOptions, NumericsJsonPolicy) which registers a coherent set of converters on a JsonSerializerOptions.

The core Bodu.Numerics types carry no [JsonConverter] attribute, so a policy takes effect only once the converters are registered. Strict is the default supplied by AddNumericsJsonConverters(JsonSerializerOptions, NumericsJsonPolicy).

Applies to

ProductVersions
.NET8, 10