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.2.x
Availability netstandard2.0
Inherited Members
JsonConverter.CanRead
JsonConverter.CanWrite
Namespace: NodaTime.Serialization.JsonNet
Assembly: NodaTime.Serialization.JsonNet.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.2.x
Availability 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.2.x
Availability 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(JsonReader, JsonSerializer)
Implemented by concrete subclasses, this performs the final conversion from a non-null JSON value to
a value of type T.
Since 1.2.x
Availability netstandard2.0
Declaration
protected override T ReadJsonImpl(JsonReader reader, JsonSerializer serializer)
Parameters
Type | Name | Description |
---|---|---|
JsonReader | reader | The JSON reader to pull data from |
JsonSerializer | serializer | The serializer to use for nested serialization |
Returns
Type | Description |
---|---|
T | The deserialized value of type T. |
Overrides
WriteJsonImpl(JsonWriter, T, JsonSerializer)
Writes the formatted value to the writer.
Since 1.2.x
Availability netstandard2.0
Declaration
protected override void WriteJsonImpl(JsonWriter writer, T value, JsonSerializer serializer)
Parameters
Type | Name | Description |
---|---|---|
JsonWriter | writer | The writer to write JSON data to |
T | value | The value to serialize |
JsonSerializer | serializer | The serializer to use for nested serialization |