Class JsonObjectSerializer
A special-purpose streaming serializer for objects to JSON. Only supports a limited number of type (boolean, DateTimeOffset, decimal, Enum, int, long, string, and trait dictionaries).
public sealed class JsonObjectSerializer : JsonSerializerBase, IDisposable
- Inheritance
-
JsonObjectSerializer
- Implements
- Inherited Members
- Extension Methods
Remarks
These types are made public for third parties only for the purpose of serializing and deserializing messages that are sent across the process boundary (that is, types which implement IMessageSinkMessage). Any other usage is not supported.
Constructors
JsonObjectSerializer(StringBuilder, Action?)
A special-purpose streaming serializer for objects to JSON. Only supports a limited number of type (boolean, DateTimeOffset, decimal, Enum, int, long, string, and trait dictionaries).
public JsonObjectSerializer(StringBuilder buffer, Action? disposeNotifier = null)
Parameters
bufferStringBuilderThe buffer to write JSON to
disposeNotifierActionAn optional callback to be notified when disposed
Remarks
These types are made public for third parties only for the purpose of serializing and deserializing messages that are sent across the process boundary (that is, types which implement IMessageSinkMessage). Any other usage is not supported.
Methods
Serialize(string, Enum?, bool)
Serialize an Enum value into the object.
public void Serialize(string key, Enum? value, bool includeNullValues = false)
Parameters
keystringThe name of the value
valueEnumThe value
includeNullValuesboolSet to
trueto serialize anullvalue, orfalseto skip it
Serialize(string, bool?, bool)
Serialize a bool value into the object.
public void Serialize(string key, bool? value, bool includeNullValues = false)
Parameters
keystringThe name of the value
valuebool?The value
includeNullValuesboolSet to
trueto serialize anullvalue, orfalseto skip it
Serialize(string, DateTimeOffset?, bool)
Serialize a DateTimeOffset value into the object.
public void Serialize(string key, DateTimeOffset? value, bool includeNullValues = false)
Parameters
keystringThe name of the value
valueDateTimeOffset?The value
includeNullValuesboolSet to
trueto serialize anullvalue, orfalseto skip it
Serialize(string, decimal?, bool)
Serialize a decimal value into the object.
public void Serialize(string key, decimal? value, bool includeNullValues = false)
Parameters
keystringThe name of the value
valuedecimal?The value
includeNullValuesboolSet to
trueto serialize anullvalue, orfalseto skip it
Serialize(string, int?, bool)
Serialize an int value into the object.
public void Serialize(string key, int? value, bool includeNullValues = false)
Parameters
keystringThe name of the value
valueint?The value
includeNullValuesboolSet to
trueto serialize anullvalue, orfalseto skip it
Serialize(string, long?, bool)
Serialize a long value into the object.
public void Serialize(string key, long? value, bool includeNullValues = false)
Parameters
keystringThe name of the value
valuelong?The value
includeNullValuesboolSet to
trueto serialize anullvalue, orfalseto skip it
Serialize(string, string?, bool, bool)
Serialize a string value into the object.
public void Serialize(string key, string? value, bool includeNullValues = false, bool includeEmptyValues = true)
Parameters
keystringThe name of the value
valuestringThe value
includeNullValuesboolSet to
trueto serialize anullvalue, orfalseto skip itincludeEmptyValuesboolSet to
trueto serialize empty strings, orfalseto skip it
SerializeArray(string)
Start serializing an array into the object.
public JsonArraySerializer SerializeArray(string key)
Parameters
keystringThe name of the array
Returns
Remarks
IMPORTANT: This serializer must be used completely and disposed before any other value is serialized into the object, or the serialization would be corrupted.
SerializeNull(string)
Serialize a null value into the object.
public void SerializeNull(string key)
Parameters
keystringThe name of the null value
SerializeObject(string)
Start serializing an object into the object.
public JsonObjectSerializer SerializeObject(string key)
Parameters
keystringThe name of the object
Returns
Remarks
IMPORTANT: This serializer must be used completely and disposed before any other value is serialized into the object, or the serialization would be corrupted.