JsonSerializerExtensions

Namespace: SnowBank.Data.Json · class

Helper methods for working with JSON converters

Methods

Deserialize

static T Deserialize<T>(IJsonDeserializer<T> serializer, string jsonText, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Deserializes a JSON text literal into an instance of type T

  • serializer — Deserializer instance to use
  • jsonText — JSON text document to parse
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Optional custom resolver

Returns: Deserialized value

static T Deserialize<T>(IJsonDeserializer<T> serializer, ReadOnlySpan<char> jsonText, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Deserializes a JSON text literal into an instance of type T

  • serializer — Deserializer instance to use
  • jsonText — JSON text document to parse
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Optional custom resolver

Returns: Deserialized value

static T Deserialize<T>(IJsonDeserializer<T> serializer, Slice jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Deserializes a JSON text literal into an instance of type T

  • serializer — Deserializer instance to use
  • jsonBytes — JSON text document to parse, encoded as UTF-8
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Optional custom resolver

Returns: Deserialized value

static T Deserialize<T>(IJsonDeserializer<T> serializer, ReadOnlySpan<byte> jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Deserializes a JSON text literal into an instance of type T

  • serializer — Deserializer instance to use
  • jsonBytes — JSON text document to parse, encoded as UTF-8
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Optional custom resolver

Returns: Deserialized value

DeserializeJsonDeserializable

static T DeserializeJsonDeserializable<T>(ReadOnlySpan<byte> jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Deserializes a JSON value into an instance of T, that is known to implement IJsonDeserializable

  • jsonBytes — UTF-8 encoded JSON document to parse
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Deserialized instance

static T DeserializeJsonDeserializable<T>(ReadOnlySpan<byte> jsonBytes, T defaultValue, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Deserializes a JSON value into an instance of T, that is known to implement IJsonDeserializable

  • jsonBytes — UTF-8 encoded JSON document to parse
  • defaultValue — Fallback value returned when jsonBytes is empty or "null".
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Deserialized instance, or defaultValue if jsonBytes is empty or "null"

FailConverterMissingDeserializerFacet

static T FailConverterMissingDeserializerFacet<T>(Type converterType)

Fails because an asymmetric converter was asked to deserialize, but only implements the packing facet

Declared as returning a value so that call sites (including generated code) can use it in expression position without unreachable-code warnings; it always throws.

static T FailConverterMissingDeserializerFacet<T>(JsonValue value, Type converterType, T defaultValue)

Deserializes an optional JSON value through an asymmetric converter that lacks the deserializing facet: an absent or null value binds to the default (the converter never runs), anything else throws

FailConverterMissingPackerFacet

static JsonValue FailConverterMissingPackerFacet(Type converterType, Type valueType)

Fails because an asymmetric converter was asked to pack, but only implements the deserializing facet

Declared as returning a value so that call sites (including generated code) can use it in expression position without unreachable-code warnings; it always throws.

JsonDeserialize

static TJsonDeserializable JsonDeserialize<TJsonDeserializable>(Slice jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

static TJsonDeserializable JsonDeserialize<TJsonDeserializable>(ReadOnlySpan<byte> jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

static TJsonDeserializable JsonDeserialize<TJsonDeserializable>(Slice jsonBytes, TJsonDeserializable defaultValue, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

static TJsonDeserializable JsonDeserialize<TJsonDeserializable>(ReadOnlySpan<byte> jsonBytes, TJsonDeserializable defaultValue, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

JsonDeserializeArrayItemNotNull

static TJsonDeserializable[] JsonDeserializeArrayItemNotNull<TJsonDeserializable>(Slice jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Deserializes a required array of non-null elements of type TJsonDeserializable

  • jsonBytes — UTF-8 encoded JSON document to parse
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Resolver used to deserialize the items of the array (optional)

Returns: Array of TJsonDeserializable elements

This method will throw if array is null, or if it contains null elements.

static TJsonDeserializable[] JsonDeserializeArrayItemNotNull<TJsonDeserializable>(ReadOnlySpan<byte> jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Deserializes a required array of non-null elements of type TJsonDeserializable

  • jsonBytes — UTF-8 encoded JSON document to parse
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Resolver used to deserialize the items of the array (optional)

Returns: Array of TJsonDeserializable elements

This method will throw if array is null, or if it contains null elements.

JsonDeserializeArrayItemOptional

static TJsonDeserializable[] JsonDeserializeArrayItemOptional<TJsonDeserializable>(Slice jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

static TJsonDeserializable[] JsonDeserializeArrayItemOptional<TJsonDeserializable>(ReadOnlySpan<byte> jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

JsonDeserializeArrayOrDefaultItemNotNull

static TJsonDeserializable[] JsonDeserializeArrayOrDefaultItemNotNull<TJsonDeserializable>(Slice jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

static TJsonDeserializable[] JsonDeserializeArrayOrDefaultItemNotNull<TJsonDeserializable>(ReadOnlySpan<byte> jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

JsonDeserializeArrayOrDefaultItemOptional

static TJsonDeserializable[] JsonDeserializeArrayOrDefaultItemOptional<TJsonDeserializable>(Slice jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

static TJsonDeserializable[] JsonDeserializeArrayOrDefaultItemOptional<TJsonDeserializable>(ReadOnlySpan<byte> jsonBytes, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

JsonPack

static JsonValue JsonPack<TJsonPackable>(TJsonPackable value, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

static JsonValue JsonPack<TJsonPackable>(TJsonPackable value, JsonValue defaultValue, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

JsonPackArray

static JsonArray JsonPackArray<TJsonPackable>(IEnumerable<TJsonPackable> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

static JsonArray JsonPackArray<TJsonPackable>(ReadOnlySpan<TJsonPackable> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

JsonPackArrayReadOnly

static JsonArray JsonPackArrayReadOnly<TJsonPackable>(IEnumerable<TJsonPackable> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

static JsonArray JsonPackArrayReadOnly<TJsonPackable>(ReadOnlySpan<TJsonPackable> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

JsonPackReadOnly

static JsonValue JsonPackReadOnly<TJsonPackable>(TJsonPackable value, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

static JsonValue JsonPackReadOnly<TJsonPackable>(TJsonPackable value, JsonValue defaultValue, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

JsonSerialize

static void JsonSerialize<TJsonSerializable>(CrystalJsonWriter writer, in TJsonSerializable value)

Serializes this instance as JSON

  • writer — Writer that will output the content of this instance
  • value — Instance to serialize (can be null)

static Slice JsonSerialize<TJsonSerializable>(in TJsonSerializable value, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a value of type TJsonSerializable into a Slice

  • value — Instance to serialize (can be null)
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom type resolver (use default behavior if null)

Returns: `123`, `true`, `"ABC"`, `{ "foo":..., "bar": ... }`, `[ ... ]`, ...

static SliceOwner JsonSerialize<TJsonSerializable>(in TJsonSerializable value, ArrayPool<byte> pool, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a value of type TJsonSerializable into a SliceOwner using the specified pool

  • value — Instance to serialize (can be null)
  • pool — Pool used to allocate the content of the slice (use Shared if null)
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom type resolver (use default behavior if null)

Returns: `123`, `true`, `"ABC"`, `{ "foo":..., "bar": ... }`, `[ ... ]`, ...

The SliceOwner returned MUST be disposed; otherwise, the rented buffer will not be returned to the pool.

JsonSerializeArray

static Slice JsonSerializeArray<TJsonSerializable>(IEnumerable<TJsonSerializable> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a sequence of values of type TJsonSerializable as a JSON Array

  • values — Sequence of instances to serialize (can be null)
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom type resolver (use default behavior if null)

Returns: `[ 123, 456, 789, ... ]`, `[ true, true, false, ... ]`, `[ "ABC", "DEF", "GHI", ... ]`, `[ { "foo":..., "bar": ... }, { "foo":..., "bar": ... }, ... ]`, `[ [ ... ], [ ... ], ... ]`, ...

static Slice JsonSerializeArray<TJsonSerializable>(ImmutableArray<TJsonSerializable> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a span of values of type TJsonSerializable as a JSON Array

  • values — Immutable array of instances to serialize
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom type resolver (use default behavior if null)

Returns: `[ 123, 456, 789, ... ]`, `[ true, true, false, ... ]`, `[ "ABC", "DEF", "GHI", ... ]`, `[ { "foo":..., "bar": ... }, { "foo":..., "bar": ... }, ... ]`, `[ [ ... ], [ ... ], ... ]`, ...

static Slice JsonSerializeArray<TJsonSerializable>(ReadOnlySpan<TJsonSerializable> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a span of values of type TJsonSerializable as a JSON Array

  • values — Span of instances to serialize
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom type resolver (use default behavior if null)

Returns: `[ 123, 456, 789, ... ]`, `[ true, true, false, ... ]`, `[ "ABC", "DEF", "GHI", ... ]`, `[ { "foo":..., "bar": ... }, { "foo":..., "bar": ... }, ... ]`, `[ [ ... ], [ ... ], ... ]`, ...

static SliceOwner JsonSerializeArray<TJsonSerializable>(IEnumerable<TJsonSerializable> values, ArrayPool<byte> pool, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a sequence of values of type TJsonSerializable as a JSON Array into a SliceOwner using the specified pool

  • values — Span of the instances to serialize (can be null)
  • pool — Pool used to allocate the content of the slice (use Shared if null)
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom type resolver (use default behavior if null)

Returns: `[ 123, 456, 789, ... ]`, `[ true, true, false, ... ]`, `[ "ABC", "DEF", "GHI", ... ]`, `[ { "foo":..., "bar": ... }, { "foo":..., "bar": ... }, ... ]`, `[ [ ... ], [ ... ], ... ]`, ...

The SliceOwner returned MUST be disposed; otherwise, the rented buffer will not be returned to the pool.

static SliceOwner JsonSerializeArray<TJsonSerializable>(ImmutableArray<TJsonSerializable> values, ArrayPool<byte> pool, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a span of values of type TJsonSerializable as a JSON Array into a SliceOwner using the specified pool

  • values — Immutable array the instances to serialize
  • pool — Pool used to allocate the content of the slice (use Shared if null)
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom type resolver (use default behavior if null)

Returns: `[ 123, 456, 789, ... ]`, `[ true, true, false, ... ]`, `[ "ABC", "DEF", "GHI", ... ]`, `[ { "foo":..., "bar": ... }, { "foo":..., "bar": ... }, ... ]`, `[ [ ... ], [ ... ], ... ]`, ...

The SliceOwner returned MUST be disposed; otherwise, the rented buffer will not be returned to the pool.

static SliceOwner JsonSerializeArray<TJsonSerializable>(ReadOnlySpan<TJsonSerializable> values, ArrayPool<byte> pool, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a span of values of type TJsonSerializable as a JSON Array into a SliceOwner using the specified pool

  • values — Span of instances to serialize
  • pool — Pool used to allocate the content of the slice (use Shared if null)
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom type resolver (use default behavior if null)

Returns: `[ 123, 456, 789, ... ]`, `[ true, true, false, ... ]`, `[ "ABC", "DEF", "GHI", ... ]`, `[ { "foo":..., "bar": ... }, { "foo":..., "bar": ... }, ... ]`, `[ [ ... ], [ ... ], ... ]`, ...

The SliceOwner returned MUST be disposed; otherwise, the rented buffer will not be returned to the pool.

JsonUnpack

static TJsonDeserializable JsonUnpack<TJsonDeserializable>(JsonValue value, ICrystalJsonTypeResolver resolver = null)

Unpacks a required instance of type TJsonDeserializable from a JsonValue

  • value — JSON value that will be bound to the new instance
  • resolver — Resolver used to deserialize the items of the array (optional)

Returns: Deserialized instance.

JsonUnpackArrayItemNotNull

static TJsonDeserializable[] JsonUnpackArrayItemNotNull<TJsonDeserializable>(JsonArray values, ICrystalJsonTypeResolver resolver = null)

Deserializes a required array of non-null elements of type TJsonDeserializable

  • values — JSON Array to deserialize
  • resolver — Resolver used to deserialize the items of the array (optional)

Returns: Array of TJsonDeserializable elements

This method will throw if array is null, or if it contains null elements.

JsonUnpackArrayItemOptional

static TJsonDeserializable[] JsonUnpackArrayItemOptional<TJsonDeserializable>(JsonArray values, ICrystalJsonTypeResolver resolver = null)

Deserializes a required array of nullable elements of type TJsonDeserializable

  • values — JSON Array to deserialize
  • resolver — Resolver used to deserialize the items of the array (optional)

Returns: Array of TJsonDeserializable elements

This method will throw if the parent does not have this field, if the field is null or not an array.

JsonUnpackArrayOrDefaultItemNotNull

static TJsonDeserializable[] JsonUnpackArrayOrDefaultItemNotNull<TJsonDeserializable>(JsonArray values, ICrystalJsonTypeResolver resolver = null)

Deserializes an optional array of non-null elements of type TJsonDeserializable

  • values — JSON Array to deserialize
  • resolver — Resolver used to deserialize the items of the array (optional)

Returns: Array of TJsonDeserializable elements, or null if it was null or missing.

This method will throw if the array contains null elements.

JsonUnpackArrayOrDefaultItemOptional

static TJsonDeserializable[] JsonUnpackArrayOrDefaultItemOptional<TJsonDeserializable>(JsonArray values, ICrystalJsonTypeResolver resolver = null)

Deserializes an optional array of nullable elements of type TJsonDeserializable

  • values — JSON Array to deserialize
  • resolver — Resolver used to deserialize the items of the array (optional)

Returns: Array of TJsonDeserializable elements, or null if it was null or missing.

JsonUnpackImmutableArrayItemNotNull

static ImmutableArray<TJsonDeserializable> JsonUnpackImmutableArrayItemNotNull<TJsonDeserializable>(JsonArray values, ICrystalJsonTypeResolver resolver = null)

JsonUnpackImmutableArrayItemOptional

static ImmutableArray<TJsonDeserializable> JsonUnpackImmutableArrayItemOptional<TJsonDeserializable>(JsonArray values, ICrystalJsonTypeResolver resolver = null)

JsonUnpackImmutableArrayOrEmptyItemNotNull

static ImmutableArray<TJsonDeserializable> JsonUnpackImmutableArrayOrEmptyItemNotNull<TJsonDeserializable>(JsonArray values, ICrystalJsonTypeResolver resolver = null)

JsonUnpackImmutableArrayOrEmptyItemOptional

static ImmutableArray<TJsonDeserializable> JsonUnpackImmutableArrayOrEmptyItemOptional<TJsonDeserializable>(JsonArray values, ICrystalJsonTypeResolver resolver = null)

JsonUnpackListItemNotNull

static List<TJsonDeserializable> JsonUnpackListItemNotNull<TJsonDeserializable>(JsonArray values, ICrystalJsonTypeResolver resolver = null)

JsonUnpackListItemOptional

static List<TJsonDeserializable> JsonUnpackListItemOptional<TJsonDeserializable>(JsonArray values, ICrystalJsonTypeResolver resolver = null)

JsonUnpackListOrDefaultItemNotNull

static List<TJsonDeserializable> JsonUnpackListOrDefaultItemNotNull<TJsonDeserializable>(JsonArray values, ICrystalJsonTypeResolver resolver = null)

JsonUnpackOrDefault

static TJsonDeserializable JsonUnpackOrDefault<TJsonDeserializable>(JsonValue value, ICrystalJsonTypeResolver resolver = null)

Unpacks an optional instance of type TJsonDeserializable from a JsonValue

  • value — JSON value that will be bound to the new instance
  • resolver — Resolver used to deserialize the items of the array (optional)

Returns: Deserialized instance, or null if value is null or missing.

Pack

static JsonValue Pack<TValue>(IJsonPacker<TValue> serializer, TValue instance, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a root value into the equivalent JsonValue, opening a fresh packing walk

  • serializer — Custom serializer
  • instance — Value to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Entry-point form of : opens a new at depth 0 and forwards. A nested caller that already holds a context must pass it instead of calling this.

PackArray

static JsonArray PackArray<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, TValue[] items)

Converts an array of items into the equivalent JsonArray, inside an already open packing walk

static JsonArray PackArray(bool[] items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts an array of Boolean into the equivalent JsonArray

  • items — Array to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackArray(int[] items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts an array of Int32 into the equivalent JsonArray

  • items — Array to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackArray(long[] items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts an array of Int64 into the equivalent JsonArray

  • items — Array to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackArray(float[] items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts an array of Single into the equivalent JsonArray

  • items — Array to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackArray(double[] items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts an array of Double into the equivalent JsonArray

  • items — Array to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackArray(string[] items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts an array of String into the equivalent JsonArray

  • items — Array to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackArray(Guid[] items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts an array of Guid into the equivalent JsonArray

  • items — Array to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackArray(Uuid128[] items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts an array of Uuid128 into the equivalent JsonArray

  • items — Array to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackArray(Uuid64[] items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts an array of Uuid64 into the equivalent JsonArray

  • items — Array to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackArray<TValue>(TValue[] items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts an array of TValue into the equivalent JsonArray

  • items — Array to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackArray<TValue>(IJsonPacker<TValue> serializer, TValue[] items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts an array of items into the equivalent JsonArray

  • serializer — Custom serializer
  • items — Items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Array, or null if items is null

PackArrayPackable

static JsonArray PackArrayPackable<TPackable>(TPackable[] items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts an array of items that implements IJsonPackable into the equivalent JsonArray

  • items — Array to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

PackDictionary

static JsonObject PackDictionary<TValue>(Dictionary<string, TValue> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a dictionary with string keys into the equivalent JsonObject

  • items — Dictionary to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonObject PackDictionary<TValue>(IDictionary<string, TValue> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a dictionary with string keys into the equivalent JsonObject

  • items — Dictionary to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonObject PackDictionary<TValue>(IEnumerable<KeyValuePair<string, TValue>> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a dictionary with string keys into the equivalent JsonObject

  • items — Dictionary to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

PackEnumNumber

static JsonValue PackEnumNumber<TEnum>(TEnum value)

Packs an enum value into its numeric form

Used by generated converters for members carrying [JsonProperty(EnumFormat = JsonEnumFormat.Number)].

PackEnumString

static JsonValue PackEnumString<TEnum>(TEnum value)

Packs an enum value into its string form, honoring any custom output tokens declared on the enum's fields

Used by generated converters for members carrying [JsonProperty(EnumFormat = JsonEnumFormat.String)].

PackEnumerable

static JsonArray PackEnumerable<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, IEnumerable<TValue> items)

Converts a sequence of items into the equivalent JsonArray, inside an already open packing walk

static JsonArray PackEnumerable(IEnumerable<bool> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a sequence of Boolean into the equivalent JsonArray

  • items — Sequence to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackEnumerable(IEnumerable<int> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a sequence of Int32 into the equivalent JsonArray

  • items — Sequence to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackEnumerable(IEnumerable<long> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a sequence of Int64 into the equivalent JsonArray

  • items — Sequence to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackEnumerable(IEnumerable<float> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a sequence of Single into the equivalent JsonArray

  • items — Sequence to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackEnumerable(IEnumerable<double> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a sequence of Double into the equivalent JsonArray

  • items — Sequence to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackEnumerable(IEnumerable<string> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a sequence of String into the equivalent JsonArray

  • items — Sequence to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackEnumerable(IEnumerable<Guid> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a sequence of Guid into the equivalent JsonArray

  • items — Sequence to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackEnumerable(IEnumerable<Uuid128> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a sequence of Uuid128 into the equivalent JsonArray

  • items — Sequence to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackEnumerable<TValue>(IEnumerable<TValue> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a sequence of TValue into the equivalent JsonArray

  • items — Sequence to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackEnumerable<TValue>(IJsonPacker<TValue> serializer, IEnumerable<TValue> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a sequence of items into the equivalent JsonArray

  • serializer — Custom serializer
  • items — Items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Array, or null if items is null

PackEnumerablePackable

static JsonArray PackEnumerablePackable<TPackable>(IEnumerable<TPackable> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a sequence of items that implements IJsonPackable into the equivalent JsonArray

  • items — Sequence to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

PackList

static JsonArray PackList<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, List<TValue> items)

Converts a list of items into the equivalent JsonArray, inside an already open packing walk

static JsonArray PackList(List<string> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a list of String into the equivalent JsonArray

  • items — List to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackList(List<bool> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a list of Boolean into the equivalent JsonArray

  • items — List to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackList(List<int> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a list of Int32 into the equivalent JsonArray

  • items — List to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackList(List<long> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a list of Int64 into the equivalent JsonArray

  • items — List to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackList(List<float> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a list of Single into the equivalent JsonArray

  • items — List to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackList(List<double> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a list of Double into the equivalent JsonArray

  • items — List to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackList(List<Guid> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a list of Guid into the equivalent JsonArray

  • items — List to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackList(List<Uuid64> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a list of Uuid64 into the equivalent JsonArray

  • items — List to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackList<TValue>(List<TValue> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a list of TValue into the equivalent JsonArray

  • items — List to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackList<TValue>(IJsonPacker<TValue> serializer, List<TValue> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a list of items into the equivalent JsonArray

  • serializer — Custom serializer
  • items — Items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Array, or null if items is null

PackListPackable

static JsonArray PackListPackable<TPackable>(List<TPackable> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a list of items that implements IJsonPackable into the equivalent JsonArray

  • items — List to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

PackNumberString

static JsonValue PackNumberString(int value)

Packs a numeric value into its string form: the number's own literal, as a string

Used by generated converters for members carrying [JsonProperty(NumberFormat = JsonNumberFormat.String)].

static JsonValue PackNumberString(uint value)

Packs a numeric value into its string form: the number's own literal, as a string

Used by generated converters for members carrying [JsonProperty(NumberFormat = JsonNumberFormat.String)].

static JsonValue PackNumberString(long value)

Packs a numeric value into its string form: the number's own literal, as a string

Used by generated converters for members carrying [JsonProperty(NumberFormat = JsonNumberFormat.String)].

static JsonValue PackNumberString(ulong value)

Packs a numeric value into its string form: the number's own literal, as a string

Used by generated converters for members carrying [JsonProperty(NumberFormat = JsonNumberFormat.String)].

static JsonValue PackNumberString(float value)

Packs a numeric value into its string form: the number's own literal, as a string

Used by generated converters for members carrying [JsonProperty(NumberFormat = JsonNumberFormat.String)].

static JsonValue PackNumberString(double value)

Packs a numeric value into its string form: the number's own literal, as a string

Used by generated converters for members carrying [JsonProperty(NumberFormat = JsonNumberFormat.String)].

static JsonValue PackNumberString(decimal value)

Packs a numeric value into its string form: the number's own literal, as a string

Used by generated converters for members carrying [JsonProperty(NumberFormat = JsonNumberFormat.String)].

static JsonValue PackNumberString(Half value)

Packs a numeric value into its string form: the number's own literal, as a string

Used by generated converters for members carrying [JsonProperty(NumberFormat = JsonNumberFormat.String)].

PackObject

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, Dictionary<string, TValue> items)

Converts the items into the equivalent JsonObject, inside an already open packing walk

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, IDictionary<string, TValue> items)

Converts the items into the equivalent JsonObject, inside an already open packing walk

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, IDictionary<string, TValue[]> items)

Converts the items into the equivalent JsonObject, inside an already open packing walk

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, ReadOnlySpan<KeyValuePair<string, TValue>> items)

Converts the items into the equivalent JsonObject, inside an already open packing walk

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, IEnumerable<KeyValuePair<string, TValue>> items)

Converts the items into the equivalent JsonObject, inside an already open packing walk

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, Dictionary<int, TValue> items)

Converts the items into the equivalent JsonObject, inside an already open packing walk

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, IDictionary<int, TValue> items)

Converts the items into the equivalent JsonObject, inside an already open packing walk

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, IDictionary<int, TValue[]> items)

Converts the items into the equivalent JsonObject, inside an already open packing walk

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, ReadOnlySpan<KeyValuePair<int, TValue>> items)

Converts the items into the equivalent JsonObject, inside an already open packing walk

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, IEnumerable<KeyValuePair<int, TValue>> items)

Converts the items into the equivalent JsonObject, inside an already open packing walk

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, Dictionary<string, TValue> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a dictionary into the equivalent JsonObject

  • serializer — Custom serializer
  • items — Dictionary to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Object, or null if items is null

Calls through the three-argument member, which carries no ambient recursion depth: a reference cycle running through this dictionary is not covered by and can still overflow the native stack.

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, IDictionary<string, TValue> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a dictionary into the equivalent JsonObject

  • serializer — Custom serializer
  • items — Dictionary to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Object, or null if items is null

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, IDictionary<string, TValue[]> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a dictionary into the equivalent JsonObject

  • serializer — Custom serializer
  • items — Dictionary to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Object, or null if items is null

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, ReadOnlySpan<KeyValuePair<string, TValue>> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a span of key/value pairs into the equivalent JsonObject

  • serializer — Custom serializer
  • items — Span to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Object, or null if items is null

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, IEnumerable<KeyValuePair<string, TValue>> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a sequence of key/value pairs into the equivalent JsonObject

  • serializer — Custom serializer
  • items — Sequence to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Object, or null if items is null

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, Dictionary<int, TValue> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a dictionary into the equivalent JsonObject

  • serializer — Custom serializer
  • items — Dictionary to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Object, or null if items is null

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, IDictionary<int, TValue> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a dictionary into the equivalent JsonObject

  • serializer — Custom serializer
  • items — Dictionary to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Object, or null if items is null

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, IDictionary<int, TValue[]> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a dictionary into the equivalent JsonObject

  • serializer — Custom serializer
  • items — Dictionary to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Object, or null if items is null

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, ReadOnlySpan<KeyValuePair<int, TValue>> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a span of key/value pairs into the equivalent JsonObject

  • serializer — Custom serializer
  • items — Span to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Object, or null if items is null

static JsonObject PackObject<TValue>(IJsonPacker<TValue> serializer, IEnumerable<KeyValuePair<int, TValue>> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a sequence of key/value pairs into the equivalent JsonObject

  • serializer — Custom serializer
  • items — Sequence to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Packed JSON Object, or null if items is null

PackSpan

static JsonArray PackSpan<TValue>(IJsonPacker<TValue> serializer, ref CrystalJsonPackContext context, ReadOnlySpan<TValue> items)

Converts a span of items into the equivalent JsonArray, inside an already open packing walk

  • serializer — Custom serializer
  • context — State of the walk, threaded into every item's Pack
  • items — Items to convert

static JsonArray PackSpan(ReadOnlySpan<bool> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a span of Boolean into the equivalent JsonArray

  • items — Span of items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackSpan(ReadOnlySpan<int> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a span of Int32 into the equivalent JsonArray

  • items — Span of items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackSpan(ReadOnlySpan<long> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a span of Int64 into the equivalent JsonArray

  • items — Span of items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackSpan(ReadOnlySpan<float> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a span of Single into the equivalent JsonArray

  • items — Span of items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackSpan(ReadOnlySpan<double> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a span of Double into the equivalent JsonArray

  • items — Span of items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackSpan(ReadOnlySpan<string> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a span of String into the equivalent JsonArray

  • items — Span of items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackSpan(ReadOnlySpan<Guid> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a span of Guid into the equivalent JsonArray

  • items — Span of items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackSpan(ReadOnlySpan<Uuid128> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a span of Uuid128 into the equivalent JsonArray

  • items — Span of items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackSpan(ReadOnlySpan<Uuid64> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a span of Uuid64 into the equivalent JsonArray

  • items — Span of items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackSpan<TValue>(ReadOnlySpan<TValue> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a span of TValue into the equivalent JsonArray

  • items — Span of items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

static JsonArray PackSpan<TValue>(IJsonPacker<TValue> serializer, ReadOnlySpan<TValue> items, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Converts a span of items into the equivalent JsonArray

  • serializer — Custom serializer
  • items — Span of items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

PackSpanPackable

static JsonArray PackSpanPackable<TPackable>(ReadOnlySpan<TPackable> items, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver)

Converts a span of items that implements IJsonPackable into the equivalent JsonArray

  • items — Span of items to convert
  • settings — Serialization settings
  • resolver — Custom resolver used to bind the value into a managed type.

ToJson

static string ToJson<TJsonSerializable>(TJsonSerializable self, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a IJsonSerializable value into a text literal

Note: if the JSON has to be sent over HTTP, or stored on disk, prefer or that will return the same result but already utf-8 encoded

static string ToJson<T>(IJsonSerializer<T> serializer, T value, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a value (of any type) into a string literal, using a customer serializer

  • serializer — Custom serializer
  • value — Instance to serialize (can be null)
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom type resolver (use default behavior if null)

Returns: `123`, `true`, `"ABC"`, `{ "foo":..., "bar": ... }`, `[ ... ]`, ...

ToJsonSlice

static Slice ToJsonSlice<TJsonSerializable>(TJsonSerializable self, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a IJsonSerializable value into a Slice, using custom settings

  • settings — Custom serialization settings
  • resolver — Custom type resolver (use default behavior if null)

Returns: Slice that contains the utf-8 encoded text representation of the JSON value

static SliceOwner ToJsonSlice<TJsonSerializable>(TJsonSerializable self, ArrayPool<byte> pool, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a IJsonSerializable value into a Slice, using custom settings

  • pool — Pool used to allocate the content of the slice (use Shared if null)
  • settings — Custom serialization settings
  • resolver — Custom type resolver (use default behavior if null)

Returns: Slice that contains the utf-8 encoded text representation of the JSON value

ToJsonText

static string ToJsonText<TJsonSerializable>(TJsonSerializable self, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a IJsonSerializable value into a text literal

Note: if the JSON has to be sent over HTTP, or stored on disk, prefer or that will return the same result but already utf-8 encoded

ToJsonTextCompact

static string ToJsonTextCompact<TJsonSerializable>(TJsonSerializable self)

Serializes a IJsonSerializable into the most compact text literal possible

Note: if the JSON has to be sent over HTTP, or stored on disk, prefer or that will return the same result but already utf-8 encoded

ToJsonTextIndented

static string ToJsonTextIndented<TJsonSerializable>(TJsonSerializable self)

Serializes a JsonValue into a human-friendly indented text representation (for logging, console output, etc...)

ToJsonValue

static JsonValue ToJsonValue<TJsonPackable>(TJsonPackable self, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Packs a IJsonPackable value into the corresponding mutable JsonValue

  • settings — Custom serialization settings
  • resolver — Optional type resolver used to bind the value into a managed CLR type (DefaultResolver is omitted)

Note: if the JSON has to be sent over HTTP, or stored on disk, prefer or that will return the same result but already utf-8 encoded

ToJsonValueReadOnly

static JsonValue ToJsonValueReadOnly<TJsonPackable>(TJsonPackable self, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Packs a IJsonPackable value into the corresponding read-only JsonValue

  • settings — Custom serialization settings
  • resolver — Optional type resolver used to bind the value into a managed CLR type (DefaultResolver is omitted)

Note: if the JSON has to be sent over HTTP, or stored on disk, prefer or that will return the same result but already utf-8 encoded

ToSlice

static Slice ToSlice<T>(IJsonSerializer<T> serializer, T value, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a value of type T into a Slice, using a customer serializer

  • serializer — Custom serializer
  • value — Instance to serialize (can be null)
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom type resolver (use default behavior if null)

Returns: `123`, `true`, `"ABC"`, `{ "foo":..., "bar": ... }`, `[ ... ]`, ...

static SliceOwner ToSlice<T>(IJsonSerializer<T> serializer, T value, ArrayPool<byte> pool, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes a value of type T into a SliceOwner, using a customer serializer, and the specified pool

  • serializer — Custom serializer
  • value — Instance to serialize (can be null)
  • pool — Pool used to allocate the content of the slice.
  • settings — Serialization settings (use default JSON settings if null)
  • resolver — Custom type resolver (use default behavior if null)

Returns: `123`, `true`, `"ABC"`, `{ "foo":..., "bar": ... }`, `[ ... ]`, ...

The SliceOwner returned MUST be disposed; otherwise, the rented buffer will not be returned to the pool.

TryUnpackArray

static bool TryUnpackArray<T>(IJsonDeserializer<T> serializer, Span<T> destination, out int written, JsonValue value, ICrystalJsonTypeResolver resolver = null)

Deserializes a JSON value into an array of T

  • serializer — Deserializer instance to use
  • destination — Destination buffer, which must be large enough to fit the deserialized elements
  • written — Number of items written into the destination
  • value — JSON value to unpack
  • resolver — Optional custom resolver

Returns: true if the deserialization was successful; otherwise, false

Unpack

static T Unpack<T>(JsonValue value, T defaultValue, ICrystalJsonTypeResolver resolver)

Deserializes a JSON value into an instance of T

  • value — JSON value to deserialize
  • defaultValue — Fallback value returned when value is null or missing.
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Deserialized instance, or defaultValue if value is null or missing

static T Unpack<T>(IJsonDeserializer<T> converter, JsonValue value, T defaultValue, ICrystalJsonTypeResolver resolver)

Deserializes a required JSON value into an instance of T

  • converter — Deserializer instance to use
  • value — JSON value to deserialize
  • defaultValue — Default value to return, if value is null or missing.
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Deserialized instance

static T Unpack<T>(JsonValue value, ICrystalJsonTypeResolver resolver, JsonValue parent = null, string fieldName = null)

Deserializes a required JSON value into an instance of T

  • value — JSON value to deserialize
  • resolver — Custom resolver used to bind the value into a managed type.
  • parent — Parent JSON object that holds this field (used when throwing exceptions).
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized instance

UnpackArray

static T[] UnpackArray<T>(IJsonDeserializer<T> serializer, JsonArray array, ICrystalJsonTypeResolver resolver = null)

Deserializes a JSON value stored in an optional field, into an array of T

  • serializer — Deserializer instance to use
  • array — JSON array to unpack
  • resolver — Optional custom resolver

Returns: Deserialized array

static T[] UnpackArray<T>(JsonValue value, T[] defaultValue = null, ICrystalJsonTypeResolver resolver = null, string fieldName = null)

Deserializes a JSON value stored in an optional field, into an array of T

  • value — JSON value to unpack
  • defaultValue — Default value to return, if value is null or missing.
  • resolver — Optional custom resolver
  • fieldName — Name of the field that holds this value in its parent objet (used when throwing exceptions)

Returns: Deserialized array

static T[] UnpackArray<T>(IJsonDeserializer<T> serializer, JsonValue value, T[] defaultValue = null, ICrystalJsonTypeResolver resolver = null, string fieldName = null)

Deserializes a JSON value stored in an optional field, into an array of T

  • serializer — Deserializer instance to use
  • value — JSON value to unpack
  • defaultValue — Default value to return, if value is null or missing.
  • resolver — Optional custom resolver
  • fieldName — Name of the field that holds this value in its parent objet (used when throwing exceptions)

Returns: Deserialized array

UnpackCollection

static TCollection UnpackCollection<TCollection, T>(IJsonDeserializer<T> serializer, JsonArray array, ICrystalJsonTypeResolver resolver = null)

Deserializes a JsonArray into a custom collection, constructed and populated via Add like a collection initializer

static TCollection UnpackCollection<TCollection, T>(IJsonDeserializer<T> serializer, JsonValue value, TCollection defaultValue = null, ICrystalJsonTypeResolver resolver = null, string fieldName = null)

Deserializes a JsonArray into a custom collection (Collection, a KeyedCollection<TKey, TItem> subclass, ...), stored into an optional field of a parent object

UnpackDictionary

static Dictionary<string, TValue> UnpackDictionary<TValue>(IJsonDeserializer<TValue> serializer, JsonObject obj, IEqualityComparer<string> keyComparer = null, ICrystalJsonTypeResolver resolver = null)

Deserializes a JsonArray into an Dictionary with String keys, stored into an optional field of a parent object

static Dictionary<string, TValue> UnpackDictionary<TValue>(IJsonDeserializer<TValue> serializer, JsonValue value, Dictionary<string, TValue> defaultValue = null, IEqualityComparer<string> keyComparer = null, ICrystalJsonTypeResolver resolver = null, string fieldName = null)

Deserializes a JsonArray into an Dictionary with String keys, stored into an optional field of a parent object

UnpackDictionaryInt32

static Dictionary<int, TValue> UnpackDictionaryInt32<TValue>(IJsonDeserializer<TValue> serializer, JsonObject obj, ICrystalJsonTypeResolver resolver = null)

Deserializes a JsonArray into an Dictionary with Int32 keys, stored into an optional field of a parent object

static Dictionary<int, TValue> UnpackDictionaryInt32<TValue>(IJsonDeserializer<TValue> serializer, JsonValue value, Dictionary<int, TValue> defaultValue = null, ICrystalJsonTypeResolver resolver = null, string fieldName = null)

Deserializes a JsonArray into an Dictionary with Int32 keys, stored into an optional field of a parent object

UnpackDoubleArray

static double[] UnpackDoubleArray(JsonValue value, double[] defaultValue = null, string fieldName = null)

Deserializes a JSON value stored in an optional field, into an array of Double.

  • value — JSON value to unpack
  • defaultValue — Default value to return, if value is null or missing.
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized array

UnpackDoubleList

static List<double> UnpackDoubleList(JsonValue value, List<double> defaultValue = null, string fieldName = null)

Deserializes a JsonArray into a List of Double, stored into an optional field of a parent object

UnpackImmutableArray

static ImmutableArray<T> UnpackImmutableArray<T>(IJsonDeserializer<T> serializer, JsonArray array, ICrystalJsonTypeResolver resolver = null)

Deserializes a JsonArray into an ImmutableArray, stored into an optional field of a parent object

static ImmutableArray<T>? UnpackImmutableArray<T>(IJsonDeserializer<T> serializer, JsonValue value, ImmutableArray<T>? defaultValue = null, ICrystalJsonTypeResolver resolver = null, string fieldName = null)

Deserializes a JsonArray into an ImmutableArray, stored into an optional field of a parent object

UnpackImmutableList

static ImmutableList<T> UnpackImmutableList<T>(IJsonDeserializer<T> serializer, JsonArray array, ICrystalJsonTypeResolver resolver = null)

Deserializes a JsonArray into an ImmutableList, stored into an optional field of a parent object

static ImmutableList<T> UnpackImmutableList<T>(IJsonDeserializer<T> serializer, JsonValue value, ImmutableList<T> defaultValue = null, ICrystalJsonTypeResolver resolver = null, string fieldName = null)

Deserializes a JsonArray into an ImmutableList, stored into an optional field of a parent object

UnpackInt32Array

static int[] UnpackInt32Array(JsonValue value, int[] defaultValue = null, string fieldName = null)

Deserializes a JSON value stored in an optional field, into an array of Int32.

  • value — JSON value to unpack
  • defaultValue — Default value to return, if value is null or missing.
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized array

UnpackInt32List

static List<int> UnpackInt32List(JsonValue value, List<int> defaultValue = null, string fieldName = null)

Deserializes a JsonArray into a List of Int32, stored into an optional field of a parent object

UnpackInt64Array

static long[] UnpackInt64Array(JsonValue value, long[] defaultValue = null, string fieldName = null)

Deserializes a JSON value stored in an optional field, into an array of Int64.

  • value — JSON value to unpack
  • defaultValue — Default value to return, if value is null or missing.
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized array

UnpackInt64List

static List<long> UnpackInt64List(JsonValue value, List<long> defaultValue = null, string fieldName = null)

Deserializes a JsonArray into a List of Int64, stored into an optional field of a parent object

UnpackJsonDeserializable

static T UnpackJsonDeserializable<T>(JsonValue value, ICrystalJsonTypeResolver resolver)

Deserializes a JSON value into an instance of T, that is known to implement IJsonDeserializable

  • value — JSON value to deserialize
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Deserialized instance, or null if value is null or missing

static T UnpackJsonDeserializable<T>(JsonValue value, T defaultValue, ICrystalJsonTypeResolver resolver)

Deserializes a JSON value into an instance of T, that is known to implement IJsonDeserializable

  • value — JSON value to deserialize
  • defaultValue — Fallback value returned when value is null or missing.
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Deserialized instance, or defaultValue if value is null or missing

UnpackList

static List<T> UnpackList<T>(IJsonDeserializer<T> serializer, JsonArray array, ICrystalJsonTypeResolver resolver = null)

Deserializes a JsonArray into a List

static List<T> UnpackList<T>(JsonValue value, List<T> defaultValue = null, ICrystalJsonTypeResolver resolver = null, string fieldName = null)

Deserializes a JsonArray into a List, stored into an optional field of a parent object

static List<T> UnpackList<T>(IJsonDeserializer<T> serializer, JsonValue value, List<T> defaultValue = null, ICrystalJsonTypeResolver resolver = null, string fieldName = null)

Deserializes a JsonArray into a List, stored into an optional field of a parent object

UnpackNullable

static T? UnpackNullable<T>(IJsonDeserializer<T> converter, JsonValue value, ICrystalJsonTypeResolver resolver)

Deserializes an optional JSON value into a Nullable, using a custom deserializer

Returns: Deserialized instance, or null if value is null or missing

UnpackNullableForm

static T? UnpackNullableForm<T>(IJsonDeserializer<T?> converter, JsonValue value, ICrystalJsonTypeResolver resolver)

Deserializes an optional JSON value into a Nullable, using a custom deserializer declared for the nullable form itself (IJsonDeserializer<T?>)

Returns: Whatever the converter answers for a present value (which may be null, e.g. for a present-but-unreadable value), or null if value is null or missing (the converter never runs)

UnpackNullableJsonDeserializable

static T? UnpackNullableJsonDeserializable<T>(JsonValue value, ICrystalJsonTypeResolver resolver)

Deserializes a JSON value into a Nullable value.

  • value — JSON value to deserialize
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Deserialized instance, or null if value is null or missing

static T? UnpackNullableJsonDeserializable<T>(JsonValue value, T? defaultValue, ICrystalJsonTypeResolver resolver)

Deserializes a JSON value into a Nullable value.

  • value — JSON value to deserialize
  • defaultValue — Fallback value returned when value is null or missing.
  • resolver — Custom resolver used to bind the value into a managed type.

Returns: Deserialized instance, or defaultValue if value is null or missing

UnpackRequired

static T UnpackRequired<T>(JsonValue value, ICrystalJsonTypeResolver resolver, JsonValue parent = null, string fieldName = null)

Deserializes a required JSON value into an instance of T

  • value — JSON value to deserialize
  • resolver — Custom resolver used to bind the value into a managed type.
  • parent — Parent JSON object that holds this field (used when throwing exceptions).
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized instance

static T UnpackRequired<T>(IJsonDeserializer<T> converter, JsonValue value, ICrystalJsonTypeResolver resolver, JsonValue parent = null, string fieldName = null)

Deserializes a required JSON value into an instance of T

  • converter — Deserializer instance to use
  • value — JSON value to deserialize
  • resolver — Custom resolver used to bind the value into a managed type.
  • parent — Parent JSON object that holds this field (used when throwing exceptions).
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized instance

UnpackRequiredArray

static T[] UnpackRequiredArray<T>(JsonValue value, ICrystalJsonTypeResolver resolver = null, JsonValue parent = null, string fieldName = null)

Deserializes a JSON value stored in a required field, into an array of T

  • value — JSON value to unpack
  • resolver — Optional custom resolver
  • parent — Parent JSON object that holds this field (used when throwing exceptions).
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized array

static T[] UnpackRequiredArray<T>(IJsonDeserializer<T> serializer, JsonValue value, ICrystalJsonTypeResolver resolver = null, JsonValue parent = null, string fieldName = null)

Deserializes a JSON value stored in a required field, into an array of T

  • serializer — Deserializer instance to use
  • value — JSON value to unpack
  • resolver — Optional custom resolver
  • parent — Parent JSON object that holds this field (used when throwing exceptions).
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized array

UnpackRequiredCollection

static TCollection UnpackRequiredCollection<TCollection, T>(IJsonDeserializer<T> serializer, JsonValue value, ICrystalJsonTypeResolver resolver = null, JsonValue parent = null, string fieldName = null)

Deserializes a JsonArray into a custom collection (Collection, a KeyedCollection<TKey, TItem> subclass, ...), stored into a required field of a parent object

UnpackRequiredDoubleArray

static double[] UnpackRequiredDoubleArray(JsonValue value, JsonValue parent = null, string fieldName = null)

Deserializes a JSON value stored in a required field, into an array of Double.

  • value — JSON value to unpack
  • parent — Parent JSON object that holds this field (used when throwing exceptions).
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized array

UnpackRequiredDoubleList

static List<double> UnpackRequiredDoubleList(JsonValue value, JsonValue parent = null, string fieldName = null)

Deserializes a JsonArray into a List of Double, stored into a required field of a parent object

UnpackRequiredInt32Array

static int[] UnpackRequiredInt32Array(JsonValue value, JsonValue parent = null, string fieldName = null)

Deserializes a JSON value stored in a required field, into an array of Int32.

  • value — JSON value to unpack
  • parent — Parent JSON object that holds this field (used when throwing exceptions).
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized array

UnpackRequiredInt32List

static List<int> UnpackRequiredInt32List(JsonValue value, JsonValue parent = null, string fieldName = null)

Deserializes a JsonArray into a List of Int32, stored into a required field of a parent object

UnpackRequiredInt64Array

static long[] UnpackRequiredInt64Array(JsonValue value, JsonValue parent = null, string fieldName = null)

Deserializes a JSON value stored in a required field, into an array of Int64.

  • value — JSON value to unpack
  • parent — Parent JSON object that holds this field (used when throwing exceptions).
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized array

UnpackRequiredInt64List

static List<long> UnpackRequiredInt64List(JsonValue value, JsonValue parent = null, string fieldName = null)

Deserializes a JsonArray into a List of Int64, stored into a required field of a parent object

UnpackRequiredJsonDeserializable

static T UnpackRequiredJsonDeserializable<T>(JsonValue value, ICrystalJsonTypeResolver resolver, JsonValue parent = null, string fieldName = null)

Deserializes a required JSON value into an instance of T, that is known to implement IJsonDeserializable

  • value — JSON value to deserialize
  • resolver — Custom resolver used to bind the value into a managed type.
  • parent — Parent JSON object that holds this field (used when throwing exceptions).
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized instance

UnpackRequiredList

static List<T> UnpackRequiredList<T>(JsonValue value, ICrystalJsonTypeResolver resolver = null, JsonValue parent = null, string fieldName = null)

Deserializes a JsonArray into a List of String, stored into a required field of a parent object

static List<T> UnpackRequiredList<T>(IJsonDeserializer<T> serializer, JsonValue value, ICrystalJsonTypeResolver resolver = null, JsonValue parent = null, string fieldName = null)

Deserializes a JsonArray into a List, stored into a required field of a parent object

UnpackRequiredNullableForm

static T? UnpackRequiredNullableForm<T>(IJsonDeserializer<T?> converter, JsonValue value, ICrystalJsonTypeResolver resolver, JsonValue parent = null, string fieldName = null)

Deserializes a required JSON value into a Nullable, using a custom deserializer declared for the nullable form itself (IJsonDeserializer<T?>)

Returns: Whatever the converter answers for a present value (which may be null, e.g. for a present-but-unreadable value)

UnpackRequiredStringArray

static string[] UnpackRequiredStringArray(JsonValue value, JsonValue parent = null, string fieldName = null)

Deserializes a JSON value stored in a required field, into an array of String.

  • value — JSON value to unpack
  • parent — Parent JSON object that holds this field (used when throwing exceptions).
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized array

UnpackRequiredStringList

static List<string> UnpackRequiredStringList(JsonValue value, JsonValue parent = null, string fieldName = null)

Deserializes a JsonArray into a List of String, stored into an optional field of a parent object

UnpackStringArray

static string[] UnpackStringArray(JsonValue value, string[] defaultValue = null, string fieldName = null)

Deserializes a JSON value stored in an optional field, into an array of String.

  • value — JSON value to unpack
  • defaultValue — Default value to return, if value is null or missing.
  • fieldName — Name of the field in the parent JSON object that holds this value (used when throwing exceptions).

Returns: Deserialized array

UnpackStringList

static List<string> UnpackStringList(JsonValue value, List<string> defaultValue = null, string fieldName = null)

Deserializes a JsonArray into a List of String, stored into a required field of a parent object

VerifyRequiredPresence

static void VerifyRequiredPresence(JsonObject obj, string fieldName)

Verifies that a member declared [DataMember(IsRequired = true)] is PRESENT in the document

  • obj — Object being bound
  • fieldName — Name of the field in the output

An explicit null SATISFIES this contract, which is what DataContractJsonSerializer does; only absence is rejected. The C# required keyword is stricter and rejects null as well.

Presence is independent of how the member's value is decoded, so generated converters emit this as a single guard per member rather than threading the condition through every decoding shape.