Class NodaConverterBase<T>
Base class for all the Json.NET converters which handle value types (which is most of them).
This handles all the boilerplate code dealing with nullity.
Since 1.2.x
Availability netstandard2.0
Inherited Members
JsonConverter.CanRead
JsonConverter.CanWrite
Namespace: NodaTime.Serialization.JsonNet
Assembly: NodaTime.Serialization.JsonNet.dll
Syntax
public abstract class NodaConverterBase<T> : JsonConverter
Type Parameters
Name | Description |
---|---|
T | The type to convert to/from JSON. |
Constructors
NodaConverterBase()
Default constructor.
Since 3.1.x
Availability netstandard2.0
Declaration
protected NodaConverterBase()
Methods
CanConvert(Type)
Returns whether or not this converter supports the given type.
Since 1.2.x
Availability 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 (including the nullable form for value types); false otherwise. |
Overrides
ReadJson(JsonReader, Type, object, JsonSerializer)
Converts the JSON stored in a reader into the relevant Noda Time type.
Since 1.2.x
Availability netstandard2.0
Declaration
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
Parameters
Type | Name | Description |
---|---|---|
JsonReader | reader | The Json.NET reader to read data from. |
Type | objectType | The type to convert the JSON to. |
object | existingValue | An existing value; ignored by this converter. |
JsonSerializer | serializer | A serializer to use for any embedded deserialization. |
Returns
Type | Description |
---|---|
object | The deserialized value. |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidNodaDataException | The JSON was invalid for this converter. |
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 abstract 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. |
WriteJson(JsonWriter, object, JsonSerializer)
Writes the given value to a Json.NET writer.
Since 1.2.x
Availability netstandard2.0
Declaration
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
Parameters
Type | Name | Description |
---|---|---|
JsonWriter | writer | The writer to write the JSON to. |
object | value | The value to write. |
JsonSerializer | serializer | The serializer to use for any embedded serialization. |
Overrides
WriteJsonImpl(JsonWriter, T, JsonSerializer)
Implemented by concrete subclasses, this performs the final write operation for a non-null value of type T
to JSON.
Since 1.2.x
Availability netstandard2.0
Declaration
protected abstract 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 |