IntervalJsonConverter<T> Class
Definition
- Assembly
- Bodu.Numerics.Serialization.Json.dll
- Package
- Bodu.Numerics.Serialization.Json 1.0.0
Converts an Interval<T> to and from JSON using the policy supplied at construction.
public sealed class IntervalJsonConverter<T> : JsonConverter<Interval<T>> where T : INumber<T>
Type Parameters
TThe numeric endpoint type of the interval.
- Inheritance
-
IntervalJsonConverter<T>
- Inherited Members
- Extension Methods
Remarks
The converter shape is selected by NumericsJsonPolicy:
-
Strict - canonical object form
{ "lower": 1, "upper": 5, "lowerInclusive": true, "upperInclusive": true }; the empty interval emits as the single-property object{ "empty": true }. A bounded side requires its endpoint value and inclusion flag; an unbounded side emits the marker"lowerUnbounded": true/"upperUnbounded": truein place of both (for example{ "lower": 1, "upperUnbounded": true, "lowerInclusive": true }for[1, +∞), or{ "lowerUnbounded": true, "upperUnbounded": true }for the whole line). Duplicate properties are rejected, and an"empty": truemarker rejects any sibling endpoint or unbounded property. -
Lenient - same object shape as Strict, with
additional tolerance:
"min"and"max"are accepted as aliases for"lower"and"upper", missing endpoint-inclusion flags default to closed (true), and a top-level JSON string is accepted and routed through TryParse(string?, IFormatProvider?, out Interval<T>) as a fallback. -
Compact - string form in ISO 31-11 bracket notation (for example
"[1, 5)") or the empty-set glyph"∅". Reads delegate to TryParse(string?, IFormatProvider?, out Interval<T>) and writes call ToString(string?, IFormatProvider?) with the invariant culture.
Constructors
IntervalJsonConverter()
Initializes a new instance of the IntervalJsonConverter<T> class configured for the Strict shape.
public IntervalJsonConverter()
IntervalJsonConverter(NumericsJsonPolicy)
Initializes a new instance of the IntervalJsonConverter<T> class configured for the supplied
policy.
public IntervalJsonConverter(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 Interval.
public override Interval<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Returns
- Interval<T>
The converted value.
Write(Utf8JsonWriter, Interval<T>, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, Interval<T> value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write to.
valueInterval<T>The value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |