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
Serialize
A static object used to indicate that something should be serialized.
protected static readonly object Serialize
Field Value
Methods
CanConvert(Type)
public override bool CanConvert(Type typeToConvert)
Parameters
typeToConvert
Type
Returns
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
TypeThe 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
Utf8JsonReaderThe Utf8JsonReader to read from.
typeToConvert
TypeThe Type being converted.
options
JsonSerializerOptionsThe JsonSerializerOptions being used.
Returns
- T
The value that was converted.
Remarks
A converter may throw any Exception, but should throw
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
JsonElementThe JsonElement.
typeToConvert
TypeThe type to return.
options
JsonSerializerOptionsThe 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
Utf8JsonWriterThe Utf8JsonWriter to write to.
value
TThe value to convert.
options
JsonSerializerOptionsThe JsonSerializerOptions being used.
Remarks
A converter may throw any Exception, but should throw
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
Utf8JsonWriterThe writer.
value
TThe value.
options
JsonSerializerOptionsThe 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
Utf8JsonWriterThe writer.
value
TThe value.
options
JsonSerializerOptionsThe 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
Utf8JsonWriterThe writer.
value
TThe value.
options
JsonSerializerOptionsThe 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
Utf8JsonWriterThe writer.
value
objectThe value.