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
writeCapableConverters
IEnumerable<JsonConverter>The additional converters.
readCapableConverters
IEnumerable<JsonConverter>Converts which are capable of reading.
prettyPrint
bool
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
jsonObject
objectThe object to convert to the concrete type.
type
TypeThe 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
T
The 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
stream
StreamThe Stream with JSON to convert.
type
TypeThe Type of object to deserialize to.
cancellationToken
CancellationTokenThe CancellationToken.
Returns
JsonToObjectAsync<T>(Stream, CancellationToken)
public Task<T?> JsonToObjectAsync<T>(Stream stream, CancellationToken cancellationToken = default)
Parameters
stream
StreamThe Stream with JSON to convert.
cancellationToken
CancellationTokenThe CancellationToken.
Returns
Type Parameters
T
The type to convert to and return.
JsonToObject<T>(string)
public T? JsonToObject<T>(string json) where T : class
Parameters
json
stringThe JSON to convert.
Returns
- T
An object of the provided Type.
Type Parameters
T
The type of object to create.
Merge(string, string)
public string Merge(string originalJson, string newContent)
Parameters
originalJson
stringThe original JSON structure to copy to.
newContent
stringThe 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
writer
Utf8JsonWriterThe Utf8JsonWriter to write the JSON to.
obj
objectThe object to convert.
ObjectToJsonAsync<T>(Stream, T, CancellationToken)
public Task ObjectToJsonAsync<T>(Stream stream, T obj, CancellationToken cancellationToken = default)
Parameters
stream
StreamThe Stream to write the JSON to.
obj
TThe object to convert.
cancellationToken
CancellationTokenThe cancellation token.
Returns
Type Parameters
T
The type to convert to a stream.
ObjectToJson<T>(T)
public string ObjectToJson<T>(T obj)
Parameters
obj
TThe object to convert.
Returns
Type Parameters
T
The type of object to create.