Class NodaPatternConverter<T>
A JSON converter for types which can be represented by a single string value, parsed or formatted
from an IPattern<T>.
Since 1.0.x
Availability net6.0, netstandard2.0
Inherited Members
Namespace: NodaTime.Serialization.SystemTextJson
Assembly: NodaTime.Serialization.SystemTextJson.dll
Syntax
public sealed class NodaPatternConverter<T> : NodaConverterBase<T>
Type Parameters
Name | Description |
---|---|
T | The type to convert to/from JSON. |
Constructors
NodaPatternConverter(IPattern<T>)
Creates a new instance with a pattern and no validator.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public NodaPatternConverter(IPattern<T> pattern)
Parameters
Type | Name | Description |
---|---|---|
IPattern<T> | pattern | The pattern to use for parsing and formatting. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | pattern is null. |
NodaPatternConverter(IPattern<T>, Action<T>)
Creates a new instance with a pattern and an optional validator. The validator will be called before each
value is written, and may throw an exception to indicate that the value cannot be serialized.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public NodaPatternConverter(IPattern<T> pattern, Action<T> validator)
Parameters
Type | Name | Description |
---|---|---|
IPattern<T> | pattern | The pattern to use for parsing and formatting. |
Action<T> | validator | The validator to call before writing values. May be null, indicating that no validation is required. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | pattern is null. |
Methods
ReadJsonImpl(ref Utf8JsonReader, JsonSerializerOptions)
Implemented by concrete subclasses, this performs the final conversion from a non-null JSON value to
a value of type T.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
protected override T ReadJsonImpl(ref Utf8JsonReader reader, JsonSerializerOptions options)
Parameters
Type | Name | Description |
---|---|---|
Utf8JsonReader | reader | The JSON reader to pull data from |
JsonSerializerOptions | options | The serializer options to use for nested serialization |
Returns
Type | Description |
---|---|
T | The deserialized value of type T. |
Overrides
WriteJsonImpl(Utf8JsonWriter, T, JsonSerializerOptions)
Writes the formatted value to the writer.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
protected override void WriteJsonImpl(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
Parameters
Type | Name | Description |
---|---|---|
Utf8JsonWriter | writer | The writer to write JSON data to |
T | value | The value to serialize |
JsonSerializerOptions | options | The serializer options to use for nested serialization |
Overrides
WriteJsonPropertyNameImpl(Utf8JsonWriter, T, JsonSerializerOptions)
Writes the formatted value to the writer.
Since 3.2.x
Availability net6.0, netstandard2.0
Declaration
protected override void WriteJsonPropertyNameImpl(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
Parameters
Type | Name | Description |
---|---|---|
Utf8JsonWriter | writer | The writer to write JSON data to. |
T | value | The value to serialize. |
JsonSerializerOptions | options | The serialization options to use for nested serialization. |