Class NodaConverterBase<T>
Base class for all the System.Text.Json converters which handle value types (which is most of them).
This deals handles all the boilerplate code dealing with nullity.
Since 1.0.x
Availability net6.0, netstandard2.0
Inherited Members
Namespace: NodaTime.Serialization.SystemTextJson
Assembly: NodaTime.Serialization.SystemTextJson.dll
Syntax
public abstract class NodaConverterBase<T> : JsonConverter<T>
Type Parameters
Name | Description |
---|---|
T | The type to convert to/from JSON. |
Constructors
NodaConverterBase()
Default constructor.
Since 3.1.x
Availability net6.0, netstandard2.0
Declaration
protected NodaConverterBase()
Methods
CanConvert(Type)
Returns whether or not this converter supports the given type.
Since 3.1.x
Availability net6.0, netstandard2.0
Declaration
public override bool CanConvert(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
Type | objectType | The type to check for compatibility. |
Returns
Type | Description |
---|---|
bool | True if the given type is supported by this converter (not including the nullable form for value types); false otherwise. |
Overrides
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Converts the JSON stored in a reader into the relevant Noda Time type.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public override T Read(ref Utf8JsonReader reader, Type objectType, JsonSerializerOptions options)
Parameters
Type | Name | Description |
---|---|---|
Utf8JsonReader | reader | The json reader to read data from. |
Type | objectType | The type to convert the JSON to. |
JsonSerializerOptions | options | A serializer options to use for any embedded deserialization. |
Returns
Type | Description |
---|---|
T | The deserialized value. |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidNodaDataException | The JSON was invalid for this converter. |
ReadAsPropertyName(ref Utf8JsonReader, Type, JsonSerializerOptions)
Converts the JSON stored in a reader into the relevant Noda Time type.
Since 3.2.x
Availability net6.0, netstandard2.0
Declaration
public override T ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
Type | Name | Description |
---|---|---|
Utf8JsonReader | reader | The json reader to read data from. |
Type | typeToConvert | The type to convert the JSON to. |
JsonSerializerOptions | options | A serializer options to use for any embedded deserialization. |
Returns
Type | Description |
---|---|
T | The deserialized value. |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidNodaDataException | The JSON was invalid for this converter. |
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 abstract 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. |
Write(Utf8JsonWriter, T, JsonSerializerOptions)
Writes the given value to a Utf8JsonWriter.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
Parameters
Type | Name | Description |
---|---|---|
Utf8JsonWriter | writer | The writer to write the JSON to. |
T | value | The value to write. |
JsonSerializerOptions | options | The serializer options to use for any embedded serialization. |
Overrides
WriteAsPropertyName(Utf8JsonWriter, T, JsonSerializerOptions)
Writes the value as a string to a Utf8JsonWriter.
Since 3.2.x
Availability net6.0, netstandard2.0
Declaration
public override void WriteAsPropertyName(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
Parameters
Type | Name | Description |
---|---|---|
Utf8JsonWriter | writer | The writer to write the JSON to. |
T | value | The value to write. |
JsonSerializerOptions | options | The serializer options to use for any embedded serialization. |
Overrides
WriteJsonImpl(Utf8JsonWriter, T, JsonSerializerOptions)
Implemented by concrete subclasses, this performs the final write operation for a non-null value of type T
to JSON.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
protected abstract 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 |
WriteJsonPropertyNameImpl(Utf8JsonWriter, T, JsonSerializerOptions)
Implemented by concrete subclasses, this performs the final write operation for a non-null value of type T
to JSON, writing the value as a property name. The default implementation throws NotImplementedException
for compatibility purposes, but all concrete classes within this package override and implement the method fully.
Since 3.2.x
Availability net6.0, netstandard2.0
Declaration
protected virtual 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 serializer options to use for nested serialization |