Table of Contents

Class JsonObjectSerializer

Namespace
Xunit.Sdk

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

buffer StringBuilder

The buffer to write JSON to

disposeNotifier Action

An 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

key string

The name of the value

value Enum

The value

includeNullValues bool

Set to true to serialize a null value, or false to skip it

Serialize(string, bool?, bool)

Serialize a bool value into the object.

public void Serialize(string key, bool? value, bool includeNullValues = false)

Parameters

key string

The name of the value

value bool?

The value

includeNullValues bool

Set to true to serialize a null value, or false to skip it

Serialize(string, DateTimeOffset?, bool)

Serialize a DateTimeOffset value into the object.

public void Serialize(string key, DateTimeOffset? value, bool includeNullValues = false)

Parameters

key string

The name of the value

value DateTimeOffset?

The value

includeNullValues bool

Set to true to serialize a null value, or false to skip it

Serialize(string, decimal?, bool)

Serialize a decimal value into the object.

public void Serialize(string key, decimal? value, bool includeNullValues = false)

Parameters

key string

The name of the value

value decimal?

The value

includeNullValues bool

Set to true to serialize a null value, or false to skip it

Serialize(string, int?, bool)

Serialize an int value into the object.

public void Serialize(string key, int? value, bool includeNullValues = false)

Parameters

key string

The name of the value

value int?

The value

includeNullValues bool

Set to true to serialize a null value, or false to skip it

Serialize(string, long?, bool)

Serialize a long value into the object.

public void Serialize(string key, long? value, bool includeNullValues = false)

Parameters

key string

The name of the value

value long?

The value

includeNullValues bool

Set to true to serialize a null value, or false to 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

key string

The name of the value

value string

The value

includeNullValues bool

Set to true to serialize a null value, or false to skip it

includeEmptyValues bool

Set to true to serialize empty strings, or false to skip it

SerializeArray(string)

Start serializing an array into the object.

public JsonArraySerializer SerializeArray(string key)

Parameters

key string

The name of the array

Returns

JsonArraySerializer

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

key string

The name of the null value

SerializeObject(string)

Start serializing an object into the object.

public JsonObjectSerializer SerializeObject(string key)

Parameters

key string

The name of the object

Returns

JsonObjectSerializer

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.