ComplexJsonConverter<T> Class
Definition
- Assembly
- Bodu.Numerics.Serialization.Json.dll
- Package
- Bodu.Numerics.Serialization.Json 1.0.0
Converts a Complex<T> to and from JSON using the policy supplied at construction.
public sealed class ComplexJsonConverter<T> : JsonConverter<Complex<T>> where T : IFloatingPointIeee754<T>
Type Parameters
TThe floating-point component type of the complex value.
- Inheritance
-
JsonConverter<Complex<T>>ComplexJsonConverter<T>
- Inherited Members
- Extension Methods
Remarks
The converter shape is selected by NumericsJsonPolicy:
-
Strict - canonical object form
{ "real": 3, "imaginary": 4 }; rejects duplicate properties and non-object tokens. A finite component is written as a JSON number; a non-finite component is written as one of the JSON strings"NaN","Infinity", or"-Infinity", since JSON numbers cannot represent those values. Either representation is accepted on read. - Lenient - same object shape as Strict, but a top-level JSON string token is accepted and routed through Parse(ReadOnlySpan<char>, IFormatProvider?) as a tolerant fallback.
-
Compact - string form
"<3; 4>"; reads delegate to TryParse(ReadOnlySpan<char>, IFormatProvider?, out Complex<T>) and writes call ToString(string?, IFormatProvider?) with the invariant culture.
Constructors
ComplexJsonConverter()
Initializes a new instance of the ComplexJsonConverter<T> class configured for the Strict shape.
public ComplexJsonConverter()
ComplexJsonConverter(NumericsJsonPolicy)
Initializes a new instance of the ComplexJsonConverter<T> class configured for the supplied
policy.
public ComplexJsonConverter(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 Bodu.Numerics.Complex{`0}.
public override Complex<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
- Complex<T>
The converted value.
Write(Utf8JsonWriter, Complex<T>, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, Complex<T> value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write to.
valueComplex<T>The value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |