Table of Contents

Class GeotabJsonConverter2<T>

Namespace
Geotab.Checkmate.Serialization
Assembly
Geotab.Checkmate.ObjectModel.dll

An abstract class used to control the conversion of objects to JSON.

public class GeotabJsonConverter2<T> : BaseJsonConverter2<T> where T : class

Type Parameters

T

The type of this converter.

Inheritance
GeotabJsonConverter2<T>
Derived
Inherited Members

Constructors

GeotabJsonConverter2()

public GeotabJsonConverter2()

Fields

DontSerialize

A static object used to indicate that something should not be serialized.

protected static readonly object DontSerialize

Field Value

object

Serialize

A static object used to indicate that something should be serialized.

protected static readonly object Serialize

Field Value

object

Methods

CanConvert(Type)

public override bool CanConvert(Type typeToConvert)

Parameters

typeToConvert Type

Returns

bool

GetProperties(Type)

Get properties for a type using a cache.

protected static (Dictionary<string, PropertyInfo> Dict, (string Name, PropertyInfo Info)[] Array) GetProperties(Type objectType)

Parameters

objectType Type

The objectType.

Returns

(Dictionary<string, PropertyInfo> Dict, (string Name, PropertyInfo Info)[] Array)

properties

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Read and convert the JSON to T.

public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

Parameters

reader Utf8JsonReader

The Utf8JsonReader to read from.

typeToConvert Type

The Type being converted.

options JsonSerializerOptions

The JsonSerializerOptions being used.

Returns

T

The value that was converted.

Remarks

A converter may throw any Exception, but should throw JsonException when the JSON is invalid.

ReadJsonCore(in JsonElement, Type, JsonSerializerOptions, HashSet<string>?)

Implementation method for read.

protected T ReadJsonCore(in JsonElement jsonElement, Type typeToConvert, JsonSerializerOptions options, HashSet<string>? keysToSkip = null)

Parameters

jsonElement JsonElement

The JsonElement.

typeToConvert Type

The type to return.

options JsonSerializerOptions

The serializer options.

keysToSkip HashSet<string>

Keys which will be skipped during reading.

Returns

T

The T.

Write(Utf8JsonWriter, T, JsonSerializerOptions)

Write the value as JSON.

public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The Utf8JsonWriter to write to.

value T

The value to convert.

options JsonSerializerOptions

The JsonSerializerOptions being used.

Remarks

A converter may throw any Exception, but should throw JsonException when the JSON cannot be created.

WriteJson(Utf8JsonWriter, T?, JsonSerializerOptions)

Same as WriteJson{JsonWriter, object, JsonSerializerOptions} but after the null check has been performed. If value is null it is OK to write.

public virtual void WriteJson(Utf8JsonWriter writer, T? value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The writer.

value T

The value.

options JsonSerializerOptions

The serializer options.

WriteObject(Utf8JsonWriter, T?, JsonSerializerOptions, Func<PropertyInfo, T, object?>?)

Creates a JSON object and writes all of value's properties to it.

protected static void WriteObject(Utf8JsonWriter writer, T? value, JsonSerializerOptions options, Func<PropertyInfo, T, object?>? getPropertyValue = null)

Parameters

writer Utf8JsonWriter

The writer.

value T

The value.

options JsonSerializerOptions

The options.

getPropertyValue Func<PropertyInfo, T, object>

Gets the value of a property with name specified as the first parameter from object in the third parameter. When overridden in a derived class properties can be excluded from serialization by returning DontSerialize.

WriteObjectProperties(Utf8JsonWriter, T, JsonSerializerOptions, Func<PropertyInfo, T, object?>?)

Writes value's properties.

protected static void WriteObjectProperties(Utf8JsonWriter writer, T value, JsonSerializerOptions options, Func<PropertyInfo, T, object?>? getPropertyValue = null)

Parameters

writer Utf8JsonWriter

The writer.

value T

The value.

options JsonSerializerOptions

The options.

getPropertyValue Func<PropertyInfo, T, object>

The get property value.

WriteSystemEntity(Utf8JsonWriter, object?)

Checks if the provided object is a System Entity. If it is it writes it and returns true, else false.

protected static bool WriteSystemEntity(Utf8JsonWriter writer, object? value)

Parameters

writer Utf8JsonWriter

The writer.

value object

The value.

Returns

bool

true if the entity is a system entity and its written.