Class BaseJsonSerializer2
- Namespace
- Geotab.Serialization
- Assembly
- Geotab.Checkmate.ObjectModel.dll
public class BaseJsonSerializer2
- Inheritance
-
BaseJsonSerializer2
- Derived
- Inherited Members
Constructors
BaseJsonSerializer2()
Initializes a new instance of the BaseJsonSerializer2 class.
public BaseJsonSerializer2()
BaseJsonSerializer2(IEnumerable<JsonConverter>?, IEnumerable<JsonConverter>?, bool)
Initializes a new instance of the BaseJsonSerializer2 class.
protected BaseJsonSerializer2(IEnumerable<JsonConverter>? writeCapableConverters, IEnumerable<JsonConverter>? readCapableConverters, bool prettyPrint = false)
Parameters
writeCapableConvertersIEnumerable<JsonConverter>The additional converters.
readCapableConvertersIEnumerable<JsonConverter>Converts which are capable of reading.
prettyPrintbool
Fields
MaxDepth
Maximum allowed depth.
public const int MaxDepth = 100
Field Value
Properties
DateTimeResolution
Gets the resolution that DateTimes will be serialized to.
protected Iso8601Resolution DateTimeResolution { get; }
Property Value
- Iso8601Resolution
The resolution that DateTimes will be serialized to.
Instance
Gets the singleton instance so contract resolvers are reused.
public static BaseJsonSerializer2 Instance { get; }
Property Value
- BaseJsonSerializer2
The singleton instance so contract resolvers are reused.
MemoryGuardCheck
Gets or sets the method that keeps track of work done, initialized by MemoryGuard.
public static Action<long>? MemoryGuardCheck { get; set; }
Property Value
ReportAllocations
Gets the method that keeps track of new object instances of allocated memory.
protected Action<long>? ReportAllocations { get; }
Property Value
Remarks
The default implementation is the value of MemoryGuardCheck.
Methods
JsonObjectToObject(object?, Type)
Converts a JsonElement to an object of the provided Type.
public object? JsonObjectToObject(object? jsonObject, Type type)
Parameters
jsonObjectobjectThe object to convert to the concrete type.
typeTypeThe Type of object to deserialize to.
Returns
JsonObjectToObject<T>(object)
Converts a JsonElement to an object of the provided Type.
public T? JsonObjectToObject<T>(object jsonObject)
Parameters
Returns
- T
An object of the provided Type.
Type Parameters
TThe type to convert to and return.
JsonToObject(Stream, Type)
public object? JsonToObject(Stream stream, Type type)
Parameters
Returns
JsonToObject(string, Type)
public object? JsonToObject(string json, Type type)
Parameters
Returns
JsonToObjectAsync(Stream, Type, CancellationToken)
public Task<object?> JsonToObjectAsync(Stream stream, Type type, CancellationToken cancellationToken = default)
Parameters
streamStreamThe Stream with JSON to convert.
typeTypeThe Type of object to deserialize to.
cancellationTokenCancellationTokenThe CancellationToken.
Returns
JsonToObjectAsync<T>(Stream, CancellationToken)
public Task<T?> JsonToObjectAsync<T>(Stream stream, CancellationToken cancellationToken = default)
Parameters
streamStreamThe Stream with JSON to convert.
cancellationTokenCancellationTokenThe CancellationToken.
Returns
Type Parameters
TThe type to convert to and return.
JsonToObject<T>(string)
public T? JsonToObject<T>(string json) where T : class
Parameters
jsonstringThe JSON to convert.
Returns
- T
An object of the provided Type.
Type Parameters
TThe type of object to create.
Merge(string, string)
public string Merge(string originalJson, string newContent)
Parameters
originalJsonstringThe original JSON structure to copy to.
newContentstringThe new JSON structure to copy from.
Returns
Exceptions
- InvalidOperationException
Throws invalid operation exception if the types content cannot be merged.
ObjectToJson(Utf8JsonWriter, object)
Converts an object to a JSON string and writes it to the provided Utf8JsonWriter.
public void ObjectToJson(Utf8JsonWriter writer, object obj)
Parameters
writerUtf8JsonWriterThe Utf8JsonWriter to write the JSON to.
objobjectThe object to convert.
ObjectToJsonAsync<T>(Stream, T, CancellationToken)
public Task ObjectToJsonAsync<T>(Stream stream, T obj, CancellationToken cancellationToken = default)
Parameters
streamStreamThe Stream to write the JSON to.
objTThe object to convert.
cancellationTokenCancellationTokenThe cancellation token.
Returns
Type Parameters
TThe type to convert to a stream.
ObjectToJson<T>(T)
public string ObjectToJson<T>(T obj)
Parameters
objTThe object to convert.
Returns
Type Parameters
TThe type of object to create.