Table of Contents

Class JsonSerializer

Namespace
Nerdbank.Json
Assembly
Nerdbank.Json.dll

Serializes .NET values to JSON.

public record JsonSerializer : IEquatable<JsonSerializer>
Inheritance
JsonSerializer
Implements
Inherited Members
Extension Methods

Remarks

This type is immutable and thread-safe.

Serialization and deserialization operation failures, including asynchronous sequence enumeration, are reported as JsonSerializationException. Existing serialization exceptions retain their instance and error code; other failures retain their original cause as the inner exception. Argument validation and OperationCanceledException when the operation's cancellation token is canceled are not wrapped.

UTF-8 buffers and caller-owned readers deserialize the first value, leaving subsequent values unread by the parser. String overloads validate a complete JSON document. Asynchronous stream overloads also validate a complete document: their temporary pipe may read ahead, so returning early could discard unread bytes when that pipe is completed. Use a caller-owned PipeReader to preserve trailing data across asynchronous operations.

When targeting .NET Standard 2.0 or .NET Framework, some important methods are available only as extension methods, so make sure to have a using Nerdbank.Json; directive in your code file to see these.

Properties

AllowTrailingCommas

Gets a value indicating whether a trailing comma is permitted before the end of a JSON array or object during deserialization.

public bool AllowTrailingCommas { get; init; }

Property Value

bool

Remarks

The default value is false.

ComparerProvider

Gets the provider of IEqualityComparer<T> and IComparer<T> instances to use when instantiating collections that support them.

public IComparerProvider? ComparerProvider { get; init; }

Property Value

IComparerProvider

The default value is an instance of SecureComparerProvider, which provides hash collision resistance for improved security when deserializing untrusted data.

Remarks

This property may be cleared from its secure default for improved performance when deserializing trusted data.

ConverterFactories

Gets the runtime-registered converter factories that are consulted after Nerdbank.Json.JsonSerializerConfiguration.Converters and Nerdbank.Json.JsonSerializerConfiguration.ConverterTypes.

public ImmutableArray<IJsonConverterFactory> ConverterFactories { get; init; }

Property Value

ImmutableArray<IJsonConverterFactory>

ConverterTypes

Gets the runtime-registered converter types that take precedence after Nerdbank.Json.JsonSerializerConfiguration.Converters.

public ConverterTypeCollection ConverterTypes { get; init; }

Property Value

ConverterTypeCollection

Converters

Gets the runtime-registered converters that take precedence over built-in and shape-based converters.

public ConverterCollection Converters { get; init; }

Property Value

ConverterCollection

DerivedTypeUnions

Gets the runtime union configuration that adds, replaces, extends, or disables shape-generated unions.

public DerivedTypeUnionCollection DerivedTypeUnions { get; init; }

Property Value

DerivedTypeUnionCollection

The default value is an empty collection.

DeserializeDefaultValues

Gets the policy that determines how deserialization handles missing or null values.

public DeserializeDefaultValuesPolicy DeserializeDefaultValues { get; init; }

Property Value

DeserializeDefaultValuesPolicy

Remarks

The default value is Default.

DictionaryKeyNamingPolicy

Gets the transformation applied to dictionary keys during serialization and deserialization.

public JsonNamingPolicy? DictionaryKeyNamingPolicy { get; init; }

Property Value

JsonNamingPolicy

Remarks

The default value is null, which preserves dictionary keys as declared.

InternStrings

Gets a value indicating whether equal strings should share an instance during deserialization.

public bool InternStrings { get; init; }

Property Value

bool

Remarks

The default value is false. When enabled, strings with equal values within one deserialization operation are represented by the same string instance.

Interned strings are retained only for the operation's lifetime, so this setting does not retain strings across deserialization operations. It can reduce memory use when input repeats string values, at the cost of looking up each deserialized string in the operation's cache.

MultiDimensionalArrayFormat

Gets the format to use when serializing multi-dimensional arrays.

public MultiDimensionalArrayFormat MultiDimensionalArrayFormat { get; init; }

Property Value

MultiDimensionalArrayFormat

The default is Nested.

PreserveReferences

Gets the mode that preserves reference equality during serialization and deserialization.

public ReferencePreservationMode PreserveReferences { get; init; }

Property Value

ReferencePreservationMode

PropertyNameCaseInsensitive

Gets a value indicating whether JSON object property names are matched case-insensitively during deserialization.

public bool PropertyNameCaseInsensitive { get; init; }

Property Value

bool

Remarks

The default value is false.

PropertyNamingPolicy

Gets the transformation applied to object property names and enum value names during serialization and deserialization.

public JsonNamingPolicy? PropertyNamingPolicy { get; init; }

Property Value

JsonNamingPolicy

Remarks

The default value is CamelCase. Set this property to null to preserve declared property names and enum value names. Enum value names are transformed only when Nerdbank.Json.JsonSerializerConfiguration.SerializeEnumValuesByName is true.

ReadCommentHandling

Gets the policy for handling JSON comments during deserialization.

public JsonCommentHandling ReadCommentHandling { get; init; }

Property Value

JsonCommentHandling

Remarks

The default value is Disallow.

SerializeDefaultValues

Gets the policy that determines whether properties with default values are serialized.

public SerializeDefaultValuesPolicy SerializeDefaultValues { get; init; }

Property Value

SerializeDefaultValuesPolicy

Remarks

The default value is Always.

SerializeEnumValuesByName

Gets a value indicating whether enum values should be serialized by name rather than by numeric value when possible.

public bool SerializeEnumValuesByName { get; init; }

Property Value

bool

Remarks

The default value is false. When enabled, Nerdbank.Json.JsonSerializerConfiguration.PropertyNamingPolicy is applied to enum value names.

StartingContext

Gets the starting context to begin serializations and deserializations with.

public SerializationContext StartingContext { get; init; }

Property Value

SerializationContext

UnionTypeAliasProvider

Gets the optional provider of custom C# union case identifiers.

public IUnionTypeAliasProvider? UnionTypeAliasProvider { get; init; }

Property Value

IUnionTypeAliasProvider

Remarks

This applies only to C# unions, not F# unions, type hierarchies, or runtime derived type mappings. Returning null for a case retains its normal identifier. Providers must be thread-safe and return consistent results while in use.

UseDiscriminatorObjects

Gets a value indicating whether unions use single-property object envelopes instead of two-element arrays.

public bool UseDiscriminatorObjects { get; init; }

Property Value

bool

The default is false.

Remarks

Integer aliases become invariant-culture property names. The reserved $base property identifies a base-contract fallback. Aliases that collide as property names or use $base are rejected in object mode. Reference preservation continues to use $id, $ref, and $value.

WriteIndented

Gets a value indicating whether serialized JSON should be formatted with indentation and line breaks.

public bool WriteIndented { get; init; }

Property Value

bool

Remarks

The default value is false.

Methods

CreateSerializationContext(ITypeShapeProvider, CancellationToken)

Creates an operation context for use by derived serializers.

protected SerializationContext CreateSerializationContext(ITypeShapeProvider provider, CancellationToken cancellationToken = default)

Parameters

provider ITypeShapeProvider

The shape provider for the operation.

cancellationToken CancellationToken

A cancellation token.

Returns

SerializationContext

The initialized context.

DeserializeArrayAsync<T>(PipeReader, ITypeShape<T>, CancellationToken)

Asynchronously streams the elements of a top-level JSON array, reading only enough to produce each element on demand.

public IAsyncEnumerable<T?> DeserializeArrayAsync<T>(PipeReader reader, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

shape ITypeShape<T>

The shape of T.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of elements.

Type Parameters

T

The element type.

DeserializeArrayAsync<T>(PipeReader, CancellationToken)

Asynchronously streams the elements of a top-level JSON array, reading only enough to produce each element on demand.

public IAsyncEnumerable<T?> DeserializeArrayAsync<T>(PipeReader reader, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of elements.

Type Parameters

T

The element type.

DeserializeArrayAsync<T>(Stream, ITypeShape<T>, CancellationToken)

Asynchronously streams the elements of a top-level JSON array from a stream.

public IAsyncEnumerable<T?> DeserializeArrayAsync<T>(Stream stream, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream to read from. It is read but not disposed or closed by this method.

shape ITypeShape<T>

The shape of T.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of elements.

Type Parameters

T

The element type.

DeserializeArrayAsync<T>(Stream, CancellationToken)

Asynchronously streams the elements of a top-level JSON array from a stream.

public IAsyncEnumerable<T?> DeserializeArrayAsync<T>(Stream stream, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

stream Stream

The stream to read from. It is read but not disposed or closed by this method.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of elements.

Type Parameters

T

The element type.

DeserializeAsync<T>(PipeReader, SerializationContext)

Deserializes a value from UTF-8 JSON read incrementally from a PipeReader using a caller-supplied starting context.

public ValueTask<T?> DeserializeAsync<T>(PipeReader reader, SerializationContext startingContext) where T : IShapeable<T>

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

startingContext SerializationContext

The context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.

Returns

ValueTask<T>

A task whose result is the deserialized value.

Type Parameters

T

The type to deserialize.

Remarks

Use this overload to supply per-call state to converters via this[object].

Exceptions

ArgumentException

Thrown if startingContext belongs to an operation already in progress.

JsonSerializationException

Thrown if deserialization fails.

DeserializeAsync<T>(PipeReader, ITypeShape<T>, SerializationContext)

Deserializes a value from UTF-8 JSON read incrementally from a PipeReader using a caller-supplied starting context.

public ValueTask<T?> DeserializeAsync<T>(PipeReader reader, ITypeShape<T> shape, SerializationContext startingContext)

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

shape ITypeShape<T>

The type shape describing T.

startingContext SerializationContext

The context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.

Returns

ValueTask<T>

A task whose result is the deserialized value.

Type Parameters

T

The type to deserialize.

Remarks

Use this overload to supply per-call state to converters via this[object].

Exceptions

ArgumentException

Thrown if startingContext belongs to an operation already in progress.

JsonSerializationException

Thrown if deserialization fails.

DeserializeAsync<T>(PipeReader, ITypeShape<T>, CancellationToken)

Deserializes the first value from UTF-8 JSON read incrementally from a PipeReader.

public ValueTask<T?> DeserializeAsync<T>(PipeReader reader, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

shape ITypeShape<T>

The type shape describing T.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<T>

A task whose result is the deserialized value.

Type Parameters

T

The type to deserialize.

Remarks

Unread bytes remain in the pipe. A scalar requires a token delimiter or end of input before it can be returned.

Exceptions

JsonSerializationException

Thrown if deserialization fails.

DeserializeAsync<T>(PipeReader, CancellationToken)

Deserializes the first value from UTF-8 JSON read incrementally from a PipeReader.

public ValueTask<T?> DeserializeAsync<T>(PipeReader reader, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<T>

A task whose result is the deserialized value.

Type Parameters

T

The type to deserialize.

Remarks

Unread bytes remain in the pipe. A scalar requires a token delimiter or end of input before it can be returned.

Exceptions

JsonSerializationException

Thrown if deserialization fails.

DeserializeAsync<T>(Stream, SerializationContext)

Deserializes a value asynchronously from a stream with per-call state.

public ValueTask<T?> DeserializeAsync<T>(Stream stream, SerializationContext startingContext) where T : IShapeable<T>

Parameters

stream Stream

The source stream, which is left open.

startingContext SerializationContext

The inactive starting context.

Returns

ValueTask<T>

The deserialized value.

Type Parameters

T

The type of value.

Remarks

Requires a complete JSON document and validates trailing trivia through the end of the stream. Use a retained caller-owned PipeReader for successive first-value reads.

DeserializeAsync<T>(Stream, ITypeShape<T>, SerializationContext)

Deserializes a value asynchronously from a stream with per-call state.

public ValueTask<T?> DeserializeAsync<T>(Stream stream, ITypeShape<T> shape, SerializationContext startingContext)

Parameters

stream Stream

The source stream, which is left open.

shape ITypeShape<T>

The shape describing the value.

startingContext SerializationContext

The inactive starting context.

Returns

ValueTask<T>

The deserialized value.

Type Parameters

T

The type of value.

Remarks

Requires a complete JSON document and validates trailing trivia through the end of the stream. Use a retained caller-owned PipeReader for successive first-value reads.

DeserializeAsync<T>(Stream, ITypeShape<T>, CancellationToken)

Deserializes a value from UTF-8 JSON read incrementally from a Stream.

public ValueTask<T?> DeserializeAsync<T>(Stream stream, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

stream Stream

The source stream. It is read but not disposed or closed by this method.

shape ITypeShape<T>

The type shape describing T.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<T>

A task whose result is the deserialized value.

Type Parameters

T

The type to deserialize.

Remarks

Requires a complete JSON document and validates trailing trivia through the end of the stream. To read successive values without losing prefetched bytes, create and retain a caller-owned PipeReader and use the pipe overloads for all subsequent reads instead of reading the underlying stream directly.

DeserializeAsync<T>(Stream, CancellationToken)

Deserializes a value from UTF-8 JSON read incrementally from a Stream.

public ValueTask<T?> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

stream Stream

The source stream. It is read but not disposed or closed by this method.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<T>

A task whose result is the deserialized value.

Type Parameters

T

The type to deserialize.

Remarks

Requires a complete JSON document and validates trailing trivia through the end of the stream. To read successive values without losing prefetched bytes, create and retain a caller-owned PipeReader and use the pipe overloads for all subsequent reads instead of reading the underlying stream directly.

DeserializeAsync<T, TProvider>(PipeReader, SerializationContext)

Deserializes a value from UTF-8 JSON read incrementally from a PipeReader using a caller-supplied starting context.

public ValueTask<T?> DeserializeAsync<T, TProvider>(PipeReader reader, SerializationContext startingContext) where TProvider : IShapeable<T>

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

startingContext SerializationContext

The context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.

Returns

ValueTask<T>

A task whose result is the deserialized value.

Type Parameters

T

The type to deserialize.

TProvider

Remarks

Use this overload to supply per-call state to converters via this[object].

Exceptions

ArgumentException

Thrown if startingContext belongs to an operation already in progress.

JsonSerializationException

Thrown if deserialization fails.

DeserializeAsync<T, TProvider>(PipeReader, CancellationToken)

Deserializes the first value from UTF-8 JSON read incrementally from a PipeReader.

public ValueTask<T?> DeserializeAsync<T, TProvider>(PipeReader reader, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<T>

A task whose result is the deserialized value.

Type Parameters

T

The type to deserialize.

TProvider

Remarks

Unread bytes remain in the pipe. A scalar requires a token delimiter or end of input before it can be returned.

Exceptions

JsonSerializationException

Thrown if deserialization fails.

DeserializeAsync<T, TProvider>(Stream, SerializationContext)

Deserializes a value asynchronously from a stream with per-call state.

public ValueTask<T?> DeserializeAsync<T, TProvider>(Stream stream, SerializationContext startingContext) where TProvider : IShapeable<T>

Parameters

stream Stream

The source stream, which is left open.

startingContext SerializationContext

The inactive starting context.

Returns

ValueTask<T>

The deserialized value.

Type Parameters

T

The type of value.

TProvider

Remarks

Requires a complete JSON document and validates trailing trivia through the end of the stream. Use a retained caller-owned PipeReader for successive first-value reads.

DeserializeAsync<T, TProvider>(Stream, CancellationToken)

Deserializes a value from UTF-8 JSON read incrementally from a Stream.

public ValueTask<T?> DeserializeAsync<T, TProvider>(Stream stream, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

stream Stream

The source stream. It is read but not disposed or closed by this method.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<T>

A task whose result is the deserialized value.

Type Parameters

T

The type to deserialize.

TProvider

Remarks

Requires a complete JSON document and validates trailing trivia through the end of the stream. To read successive values without losing prefetched bytes, create and retain a caller-owned PipeReader and use the pipe overloads for all subsequent reads instead of reading the underlying stream directly.

DeserializeEnumerableAsync<T>(PipeReader, SequenceOptions, CancellationToken)

Asynchronously streams JSON values using the selected framing.

public IAsyncEnumerable<T?> DeserializeEnumerableAsync<T>(PipeReader reader, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of values.

Type Parameters

T

The value type.

Exceptions

JsonSerializationException

Thrown if deserialization or newline framing fails.

DeserializeEnumerableAsync<T>(PipeReader, ITypeShape<T>, SequenceOptions, CancellationToken)

Asynchronously streams JSON values using the selected framing.

public IAsyncEnumerable<T?> DeserializeEnumerableAsync<T>(PipeReader reader, ITypeShape<T> shape, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

shape ITypeShape<T>

The shape of T.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of values.

Type Parameters

T

The value type.

Exceptions

JsonSerializationException

Thrown if deserialization or newline framing fails.

DeserializeEnumerableAsync<T>(Stream, SequenceOptions, CancellationToken)

Asynchronously streams JSON values from a stream using the selected framing.

public IAsyncEnumerable<T?> DeserializeEnumerableAsync<T>(Stream stream, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

stream Stream

The stream to read from. It is read but not disposed or closed by this method.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of values.

Type Parameters

T

The value type.

DeserializeEnumerableAsync<T>(Stream, ITypeShape<T>, SequenceOptions, CancellationToken)

Asynchronously streams JSON values from a stream using the selected framing.

public IAsyncEnumerable<T?> DeserializeEnumerableAsync<T>(Stream stream, ITypeShape<T> shape, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream to read from. It is read but not disposed or closed by this method.

shape ITypeShape<T>

The shape of T.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of values.

Type Parameters

T

The value type.

DeserializeEnumerableAsync<T, TProvider>(PipeReader, SequenceOptions, CancellationToken)

Asynchronously streams JSON values using the selected framing.

public IAsyncEnumerable<T?> DeserializeEnumerableAsync<T, TProvider>(PipeReader reader, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of values.

Type Parameters

T

The value type.

TProvider

Exceptions

JsonSerializationException

Thrown if deserialization or newline framing fails.

DeserializeEnumerableAsync<T, TProvider>(Stream, SequenceOptions, CancellationToken)

Asynchronously streams JSON values from a stream using the selected framing.

public IAsyncEnumerable<T?> DeserializeEnumerableAsync<T, TProvider>(Stream stream, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

stream Stream

The stream to read from. It is read but not disposed or closed by this method.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<T>

An asynchronous sequence of values.

Type Parameters

T

The value type.

TProvider

DeserializeJsonValue(scoped in ReadOnlySequence<byte>, CancellationToken)

Deserializes the first UTF-8 JSON value, possibly spanning multiple segments, into the native JsonValue document object model.

public JsonValue? DeserializeJsonValue(scoped in ReadOnlySequence<byte> utf8Json, CancellationToken cancellationToken = default)

Parameters

utf8Json ReadOnlySequence<byte>

The UTF-8 JSON bytes, possibly spanning multiple segments.

cancellationToken CancellationToken

A cancellation token.

Returns

JsonValue

The parsed value.

DeserializeJsonValue(Stream, CancellationToken)

Deserializes the first UTF-8 JSON value from a stream into the native JsonValue document object model.

public JsonValue? DeserializeJsonValue(Stream stream, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream. It is read but not disposed by this method.

cancellationToken CancellationToken

A cancellation token.

Returns

JsonValue

The parsed value.

Remarks

The stream is buffered to its end and left open.

DeserializeJsonValue(ReadOnlyMemory<byte>, CancellationToken)

Deserializes the first UTF-8 JSON value into the native JsonValue document object model.

public JsonValue? DeserializeJsonValue(ReadOnlyMemory<byte> utf8Json, CancellationToken cancellationToken = default)

Parameters

utf8Json ReadOnlyMemory<byte>

The UTF-8 JSON bytes.

cancellationToken CancellationToken

A cancellation token.

Returns

JsonValue

The parsed value.

DeserializeJsonValue(string, CancellationToken)

Deserializes any JSON text into the native, dependency-free JsonValue document object model.

public JsonValue? DeserializeJsonValue(string json, CancellationToken cancellationToken = default)

Parameters

json string

The JSON text.

cancellationToken CancellationToken

A cancellation token.

Returns

JsonValue

The parsed value.

Remarks

This entry point does not require a static model or a generated shape, and it neither roots System.Text.Json nor uses reflection, so it keeps the default serializer trimming- and NativeAOT-safe.

DeserializeJsonValueAsync(PipeReader, CancellationToken)

Deserializes the first UTF-8 JSON value from a PipeReader into the native JsonValue document object model, reading incrementally without buffering the whole document.

public ValueTask<JsonValue?> DeserializeJsonValueAsync(PipeReader reader, CancellationToken cancellationToken = default)

Parameters

reader PipeReader

The pipe. It is advanced but not completed by this method.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<JsonValue>

The parsed value.

Remarks

Unread bytes remain in the pipe for the caller.

DeserializeJsonValueAsync(Stream, CancellationToken)

Deserializes JSON from a Stream into the native JsonValue document object model.

public ValueTask<JsonValue?> DeserializeJsonValueAsync(Stream stream, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream. It is read but not disposed by this method.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<JsonValue>

The parsed value.

DeserializeObject(ref JsonReader, ITypeShape, SerializationContext)

Deserializes an untyped value from JSON using the specified type shape and a caller-supplied starting context.

public object? DeserializeObject(ref JsonReader reader, ITypeShape shape, SerializationContext startingContext)

Parameters

reader JsonReader

The reader to deserialize the value from.

shape ITypeShape

The type shape describing the structure of the value to deserialize.

startingContext SerializationContext

The context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.

Returns

object

The deserialized value, or null if the JSON represents a null value.

Exceptions

ArgumentException

Thrown if startingContext belongs to an operation already in progress.

DeserializeObject(ref JsonReader, ITypeShape, CancellationToken)

Deserializes an untyped value from JSON using the specified type shape.

public object? DeserializeObject(ref JsonReader reader, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

reader JsonReader

The reader to deserialize the value from.

shape ITypeShape

The type shape describing the structure of the value to deserialize.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

object

The deserialized value, or null if the JSON represents a null value.

DeserializeObject(scoped in ReadOnlySequence<byte>, ITypeShape, CancellationToken)

Deserializes an untyped value from JSON using the specified type shape.

public object? DeserializeObject(scoped in ReadOnlySequence<byte> buffer, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

buffer ReadOnlySequence<byte>

The JSON to deserialize from.

shape ITypeShape

The type shape describing the structure of the value to deserialize.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

object

The deserialized value, or null if the JSON represents a null value.

DeserializeObject(Stream, ITypeShape, CancellationToken)

Deserializes an untyped value from JSON using the specified type shape.

public object? DeserializeObject(Stream stream, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

stream Stream

The JSON stream.

shape ITypeShape

The type shape describing the structure of the value to deserialize.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

object

The deserialized value, or null if the JSON represents a null value.

DeserializeObject(ReadOnlyMemory<byte>, ITypeShape, CancellationToken)

Deserializes an untyped value from JSON using the specified type shape.

public object? DeserializeObject(ReadOnlyMemory<byte> buffer, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

buffer ReadOnlyMemory<byte>
shape ITypeShape

The type shape describing the structure of the value to deserialize.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

object

The deserialized value, or null if the JSON represents a null value.

DeserializeObject(string, ITypeShape, CancellationToken)

Deserializes an untyped value from JSON using the specified type shape.

public object? DeserializeObject(string json, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

json string
shape ITypeShape

The type shape describing the structure of the value to deserialize.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

object

The deserialized value, or null if the JSON represents a null value.

DeserializeObjectAsync(PipeReader, ITypeShape, SerializationContext)

Deserializes an untyped value asynchronously from a pipe using per-call state.

public ValueTask<object?> DeserializeObjectAsync(PipeReader reader, ITypeShape shape, SerializationContext startingContext)

Parameters

reader PipeReader

The source pipe, which is not completed.

shape ITypeShape

The shape describing the value.

startingContext SerializationContext

The inactive starting context for this operation.

Returns

ValueTask<object>

The deserialized value.

DeserializeObjectAsync(PipeReader, ITypeShape, CancellationToken)

Deserializes an untyped value asynchronously from a pipe.

public ValueTask<object?> DeserializeObjectAsync(PipeReader reader, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

reader PipeReader

The source pipe, which is not completed.

shape ITypeShape

The shape describing the value.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<object>

The deserialized value.

DeserializeObjectAsync(Stream, ITypeShape, SerializationContext)

Deserializes an untyped value asynchronously from a stream using per-call state.

public ValueTask<object?> DeserializeObjectAsync(Stream stream, ITypeShape shape, SerializationContext startingContext)

Parameters

stream Stream

The source stream, which is left open.

shape ITypeShape

The shape describing the value.

startingContext SerializationContext

The inactive starting context for this operation.

Returns

ValueTask<object>

The deserialized value.

Remarks

Requires a complete JSON document and validates trailing trivia through the end of the stream. Use a retained caller-owned PipeReader for successive first-value reads.

DeserializeObjectAsync(Stream, ITypeShape, CancellationToken)

Deserializes an untyped value asynchronously from a stream.

public ValueTask<object?> DeserializeObjectAsync(Stream stream, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

stream Stream

The source stream, which is left open.

shape ITypeShape

The shape describing the value.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask<object>

The deserialized value.

Remarks

Requires a complete JSON document and validates trailing trivia through the end of the stream. Use a retained caller-owned PipeReader for successive first-value reads.

DeserializePathEnumerableAsync<TElement>(PipeReader, JsonPath, MissingPathBehavior, CancellationToken)

Asynchronously streams the elements of a JSON array selected by a pre-parsed JsonPath inside an object or array envelope, parsing the preamble incrementally and draining the remainder of the envelope on completion.

public IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement>(PipeReader reader, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TElement : IShapeable<TElement>

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

path JsonPath

The pre-parsed path that selects the array. Names are the serialized (wire) names.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

An asynchronous sequence of elements.

Type Parameters

TElement

The element type.

DeserializePathEnumerableAsync<TElement>(PipeReader, JsonPath, ITypeShape<TElement>, MissingPathBehavior, CancellationToken)

Asynchronously streams the elements of a JSON array selected by a pre-parsed JsonPath inside an object or array envelope, parsing the preamble incrementally and draining the remainder of the envelope on completion.

public IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement>(PipeReader reader, JsonPath path, ITypeShape<TElement> elementShape, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

path JsonPath

The pre-parsed path that selects the array. Names are the serialized (wire) names.

elementShape ITypeShape<TElement>

The shape of TElement.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

An asynchronous sequence of elements.

Type Parameters

TElement

The element type.

DeserializePathEnumerableAsync<TElement>(Stream, JsonPath, MissingPathBehavior, CancellationToken)

Asynchronously streams the elements of a JSON array selected by a pre-parsed JsonPath from a stream.

public IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement>(Stream stream, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TElement : IShapeable<TElement>

Parameters

stream Stream

The stream to read from. It is read but not disposed or closed by this method.

path JsonPath

The pre-parsed path that selects the array.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

An asynchronous sequence of elements.

Type Parameters

TElement

The element type.

DeserializePathEnumerableAsync<TElement>(Stream, JsonPath, ITypeShape<TElement>, MissingPathBehavior, CancellationToken)

Asynchronously streams the elements of a JSON array selected by a pre-parsed JsonPath from a stream.

public IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement>(Stream stream, JsonPath path, ITypeShape<TElement> elementShape, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream to read from. It is read but not disposed or closed by this method.

path JsonPath

The pre-parsed path that selects the array.

elementShape ITypeShape<TElement>

The shape of TElement.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

An asynchronous sequence of elements.

Type Parameters

TElement

The element type.

DeserializePathEnumerableAsync<TElement, TProvider>(PipeReader, JsonPath, MissingPathBehavior, CancellationToken)

Asynchronously streams the elements of a JSON array selected by a pre-parsed JsonPath inside an object or array envelope, parsing the preamble incrementally and draining the remainder of the envelope on completion.

public IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement, TProvider>(PipeReader reader, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TProvider : IShapeable<TElement>

Parameters

reader PipeReader

The pipe to read from. It is advanced but never completed by this method.

path JsonPath

The pre-parsed path that selects the array. Names are the serialized (wire) names.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

An asynchronous sequence of elements.

Type Parameters

TElement

The element type.

TProvider

DeserializePathEnumerableAsync<TRoot, TElement>(PipeReader, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)

Streams the array selected by a typed path, without buffering the enclosing document.

public IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement>(PipeReader reader, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TRoot : IShapeable<TRoot>

Parameters

reader PipeReader

The input pipe. options controls whether it is completed.

options JsonSerializer.StreamingEnumerationOptions<TRoot, TElement>

The path, missing-path behavior, and pipe ownership options.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

The selected array elements.

Type Parameters

TRoot

The root document type, which supplies its shape.

TElement

The selected array element type.

Remarks

Full enumeration drains the JSON envelope. Early disposal leaves the pipe at the last consumed token, not at a new JSON document.

DeserializePathEnumerableAsync<TRoot, TElement>(PipeReader, ITypeShape<TRoot>, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)

Streams the array selected by a typed path, without buffering the enclosing document.

public IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement>(PipeReader reader, ITypeShape<TRoot> shape, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

reader PipeReader

The input pipe. Ownership is controlled by options.

shape ITypeShape<TRoot>

The root type shape.

options JsonSerializer.StreamingEnumerationOptions<TRoot, TElement>

The path and enumeration options.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

The selected array elements.

Type Parameters

TRoot

The root document type.

TElement

The element type.

Remarks

Full enumeration drains the JSON envelope. Early disposal leaves the pipe at the last consumed token, not at a new JSON document.

DeserializePathEnumerableAsync<TElement, TProvider>(Stream, JsonPath, MissingPathBehavior, CancellationToken)

Asynchronously streams the elements of a JSON array selected by a pre-parsed JsonPath from a stream.

public IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement, TProvider>(Stream stream, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TProvider : IShapeable<TElement>

Parameters

stream Stream

The stream to read from. It is read but not disposed or closed by this method.

path JsonPath

The pre-parsed path that selects the array.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

An asynchronous sequence of elements.

Type Parameters

TElement

The element type.

TProvider

DeserializePathEnumerableAsync<TRoot, TElement>(Stream, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)

Streams the array selected by a typed path, without buffering the enclosing document.

public IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement>(Stream stream, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TRoot : IShapeable<TRoot>

Parameters

stream Stream

The input stream, which remains open.

options JsonSerializer.StreamingEnumerationOptions<TRoot, TElement>

The path and enumeration options. The internally created pipe is always completed.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

The selected array elements.

Type Parameters

TRoot

The root document type, which supplies its shape.

TElement

The selected array element type.

Remarks

Full enumeration drains the JSON envelope. Early disposal leaves the pipe at the last consumed token, not at a new JSON document.

DeserializePathEnumerableAsync<TRoot, TElement>(Stream, ITypeShape<TRoot>, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)

Streams the array selected by a typed path, without buffering the enclosing document.

public IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement>(Stream stream, ITypeShape<TRoot> shape, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

stream Stream

The input stream, which remains open.

shape ITypeShape<TRoot>

The root type shape.

options JsonSerializer.StreamingEnumerationOptions<TRoot, TElement>

The path and enumeration options. The internally created pipe is always completed.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

The selected array elements.

Type Parameters

TRoot

The root document type.

TElement

The element type.

Remarks

Full enumeration drains the JSON envelope. Early disposal leaves the pipe at the last consumed token, not at a new JSON document.

DeserializePathEnumerableAsync<TRoot, TElement, TProvider>(PipeReader, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)

Streams the array selected by a typed path, without buffering the enclosing document.

public IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement, TProvider>(PipeReader reader, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TProvider : IShapeable<TRoot>

Parameters

reader PipeReader

The input pipe. options controls whether it is completed.

options JsonSerializer.StreamingEnumerationOptions<TRoot, TElement>

The path, missing-path behavior, and pipe ownership options.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

The selected array elements.

Type Parameters

TRoot

The root document type.

TElement

The selected array element type.

TProvider

The root type shape witness.

Remarks

Full enumeration drains the JSON envelope. Early disposal leaves the pipe at the last consumed token, not at a new JSON document.

DeserializePathEnumerableAsync<TRoot, TElement, TProvider>(Stream, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)

Streams the array selected by a typed path, without buffering the enclosing document.

public IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement, TProvider>(Stream stream, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TProvider : IShapeable<TRoot>

Parameters

stream Stream

The input stream, which remains open.

options JsonSerializer.StreamingEnumerationOptions<TRoot, TElement>

The path and enumeration options. The internally created pipe is always completed.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TElement>

The selected array elements.

Type Parameters

TRoot

The root document type.

TElement

The selected array element type.

TProvider

The root type shape witness.

Remarks

Full enumeration drains the JSON envelope. Early disposal leaves the pipe at the last consumed token, not at a new JSON document.

DeserializePath<TValue>(ref JsonReader, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes a raw JSON path from a reader.

public TValue? DeserializePath<TValue>(ref JsonReader reader, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TValue : IShapeable<TValue>

Parameters

reader JsonReader

The reader positioned at the document.

path JsonPath

The raw path to select.

missingBehavior MissingPathBehavior

The behavior for a missing path.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The selected value.

Type Parameters

TValue

The selected value type.

DeserializePath<TValue>(ref JsonReader, JsonPath, ITypeShape<TValue>, MissingPathBehavior, CancellationToken)

Deserializes a raw JSON path from a reader.

public TValue? DeserializePath<TValue>(ref JsonReader reader, JsonPath path, ITypeShape<TValue> targetShape, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

reader JsonReader

The reader positioned at the document.

path JsonPath

The raw path to select.

targetShape ITypeShape<TValue>

The selected value shape.

missingBehavior MissingPathBehavior

The behavior for a missing path.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The selected value.

Type Parameters

TValue

The selected value type.

DeserializePath<TValue>(scoped in ReadOnlySequence<byte>, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath from a possibly multi-segment UTF-8 buffer.

public TValue? DeserializePath<TValue>(scoped in ReadOnlySequence<byte> utf8Json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TValue : IShapeable<TValue>

Parameters

utf8Json ReadOnlySequence<byte>

The UTF-8 JSON document, possibly spanning multiple buffer segments.

path JsonPath

The pre-parsed path that selects the value.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value when the path is missing and default behavior is selected.

Type Parameters

TValue

The type of the selected value.

DeserializePath<TValue>(scoped in ReadOnlySequence<byte>, JsonPath, ITypeShape<TValue>, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath from a possibly multi-segment UTF-8 buffer.

public TValue? DeserializePath<TValue>(scoped in ReadOnlySequence<byte> utf8Json, JsonPath path, ITypeShape<TValue> targetShape, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

utf8Json ReadOnlySequence<byte>

The UTF-8 JSON document, possibly spanning multiple buffer segments.

path JsonPath

The pre-parsed path that selects the value.

targetShape ITypeShape<TValue>

The shape of TValue.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value when the path is missing and default behavior is selected.

Type Parameters

TValue

The type of the selected value.

DeserializePath<TValue>(Stream, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes a raw JSON path from a stream.

public TValue? DeserializePath<TValue>(Stream stream, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TValue : IShapeable<TValue>

Parameters

stream Stream

The document stream, which is read to its end and remains open.

path JsonPath

The raw JSON path.

missingBehavior MissingPathBehavior

The behavior for a missing path.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The selected value.

Type Parameters

TValue

The selected value type.

DeserializePath<TValue>(Stream, JsonPath, ITypeShape<TValue>, MissingPathBehavior, CancellationToken)

Deserializes a raw JSON path from a stream.

public TValue? DeserializePath<TValue>(Stream stream, JsonPath path, ITypeShape<TValue> targetShape, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

stream Stream

The document stream, which is read to its end and remains open.

path JsonPath

The raw JSON path.

targetShape ITypeShape<TValue>

The selected value shape.

missingBehavior MissingPathBehavior

The behavior for a missing path.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The selected value.

Type Parameters

TValue

The selected value type.

DeserializePath<TValue>(ReadOnlyMemory<byte>, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath from a UTF-8 buffer.

public TValue? DeserializePath<TValue>(ReadOnlyMemory<byte> utf8Json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TValue : IShapeable<TValue>

Parameters

utf8Json ReadOnlyMemory<byte>

The UTF-8 JSON document.

path JsonPath

The pre-parsed path that selects the value.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value when the path is missing and default behavior is selected.

Type Parameters

TValue

The type of the selected value.

DeserializePath<TValue>(ReadOnlyMemory<byte>, JsonPath, ITypeShape<TValue>, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath from a UTF-8 buffer.

public TValue? DeserializePath<TValue>(ReadOnlyMemory<byte> utf8Json, JsonPath path, ITypeShape<TValue> targetShape, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

utf8Json ReadOnlyMemory<byte>

The UTF-8 JSON document.

path JsonPath

The pre-parsed path that selects the value.

targetShape ITypeShape<TValue>

The shape of TValue.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value when the path is missing and default behavior is selected.

Type Parameters

TValue

The type of the selected value.

DeserializePath<TValue>(string, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath, using the type's own shape.

public TValue? DeserializePath<TValue>(string json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TValue : IShapeable<TValue>

Parameters

json string

The JSON document.

path JsonPath

The pre-parsed path that selects the value.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value.

Type Parameters

TValue

The type of the selected value.

DeserializePath<TValue>(string, JsonPath, ITypeShape<TValue>, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath, skipping unrelated JSON.

public TValue? DeserializePath<TValue>(string json, JsonPath path, ITypeShape<TValue> targetShape, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)

Parameters

json string

The JSON document.

path JsonPath

The pre-parsed path that selects the value.

targetShape ITypeShape<TValue>

The shape of TValue.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value if the path is missing and missingBehavior is ReturnDefault.

Type Parameters

TValue

The type of the selected value.

Remarks

The selected value is deserialized through the full converter graph, so naming policies, custom converters, and union envelopes remain correct for the target. Path segments navigate plain JSON objects and arrays; targeted deserialization is not supported when reference preservation is enabled.

DeserializePath<TValue, TProvider>(ref JsonReader, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes a raw JSON path from a reader.

public TValue? DeserializePath<TValue, TProvider>(ref JsonReader reader, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TProvider : IShapeable<TValue>

Parameters

reader JsonReader

The reader positioned at the document.

path JsonPath

The raw path to select.

missingBehavior MissingPathBehavior

The behavior for a missing path.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The selected value.

Type Parameters

TValue

The selected value type.

TProvider

DeserializePath<TRoot, TElement>(ref JsonReader, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement>(ref JsonReader reader, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TRoot : IShapeable<TRoot>

Parameters

reader JsonReader

The reader positioned at the root document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type, which supplies its shape.

TElement

The selected value type.

DeserializePath<TRoot, TElement>(ref JsonReader, ITypeShape<TRoot>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement>(ref JsonReader reader, ITypeShape<TRoot> shape, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

reader JsonReader

The reader positioned at the root document.

shape ITypeShape<TRoot>

The root type shape.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

DeserializePath<TValue, TProvider>(scoped in ReadOnlySequence<byte>, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath from a possibly multi-segment UTF-8 buffer.

public TValue? DeserializePath<TValue, TProvider>(scoped in ReadOnlySequence<byte> utf8Json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TProvider : IShapeable<TValue>

Parameters

utf8Json ReadOnlySequence<byte>

The UTF-8 JSON document, possibly spanning multiple buffer segments.

path JsonPath

The pre-parsed path that selects the value.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value when the path is missing and default behavior is selected.

Type Parameters

TValue

The type of the selected value.

TProvider

DeserializePath<TRoot, TElement>(scoped in ReadOnlySequence<byte>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement>(scoped in ReadOnlySequence<byte> utf8Json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TRoot : IShapeable<TRoot>

Parameters

utf8Json ReadOnlySequence<byte>

The possibly segmented UTF-8 document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type, which supplies its shape.

TElement

The selected value type.

DeserializePath<TRoot, TElement>(scoped in ReadOnlySequence<byte>, ITypeShape<TRoot>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement>(scoped in ReadOnlySequence<byte> utf8Json, ITypeShape<TRoot> shape, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

utf8Json ReadOnlySequence<byte>

The possibly segmented UTF-8 document.

shape ITypeShape<TRoot>

The root type shape.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

DeserializePath<TValue, TProvider>(Stream, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes a raw JSON path from a stream.

public TValue? DeserializePath<TValue, TProvider>(Stream stream, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TProvider : IShapeable<TValue>

Parameters

stream Stream

The document stream, which is read to its end and remains open.

path JsonPath

The raw JSON path.

missingBehavior MissingPathBehavior

The behavior for a missing path.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The selected value.

Type Parameters

TValue

The selected value type.

TProvider

DeserializePath<TRoot, TElement>(Stream, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement>(Stream stream, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TRoot : IShapeable<TRoot>

Parameters

stream Stream

The document stream, which is read to its end and remains open.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type, which supplies its shape.

TElement

The selected value type.

DeserializePath<TRoot, TElement>(Stream, ITypeShape<TRoot>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement>(Stream stream, ITypeShape<TRoot> shape, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

stream Stream

The document stream, which remains open. The stream is read to its end.

shape ITypeShape<TRoot>

The root type shape.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

DeserializePath<TValue, TProvider>(ReadOnlyMemory<byte>, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath from a UTF-8 buffer.

public TValue? DeserializePath<TValue, TProvider>(ReadOnlyMemory<byte> utf8Json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TProvider : IShapeable<TValue>

Parameters

utf8Json ReadOnlyMemory<byte>

The UTF-8 JSON document.

path JsonPath

The pre-parsed path that selects the value.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value, or the default value when the path is missing and default behavior is selected.

Type Parameters

TValue

The type of the selected value.

TProvider

DeserializePath<TRoot, TElement>(ReadOnlyMemory<byte>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement>(ReadOnlyMemory<byte> utf8Json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TRoot : IShapeable<TRoot>

Parameters

utf8Json ReadOnlyMemory<byte>

The UTF-8 document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type, which supplies its shape.

TElement

The selected value type.

DeserializePath<TRoot, TElement>(ReadOnlyMemory<byte>, ITypeShape<TRoot>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement>(ReadOnlyMemory<byte> utf8Json, ITypeShape<TRoot> shape, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

utf8Json ReadOnlyMemory<byte>

The UTF-8 document.

shape ITypeShape<TRoot>

The root type shape.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

DeserializePath<TValue, TProvider>(string, JsonPath, MissingPathBehavior, CancellationToken)

Deserializes only the value selected by a pre-parsed JsonPath, using a witness type's shape.

public TValue? DeserializePath<TValue, TProvider>(string json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default) where TProvider : IShapeable<TValue>

Parameters

json string

The JSON document.

path JsonPath

The pre-parsed path that selects the value.

missingBehavior MissingPathBehavior

Controls behavior when the path is not found.

cancellationToken CancellationToken

A cancellation token.

Returns

TValue

The deserialized value.

Type Parameters

TValue

The type of the selected value.

TProvider

A witness type that provides the shape for TValue.

DeserializePath<TRoot, TElement>(string, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement>(string json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TRoot : IShapeable<TRoot>

Parameters

json string

The JSON document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type, which supplies its shape.

TElement

The selected value type.

DeserializePath<TRoot, TElement>(string, ITypeShape<TRoot>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement>(string json, ITypeShape<TRoot> shape, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)

Parameters

json string

The JSON document.

shape ITypeShape<TRoot>

The root type shape.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

DeserializePath<TRoot, TElement, TProvider>(ref JsonReader, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement, TProvider>(ref JsonReader reader, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TProvider : IShapeable<TRoot>

Parameters

reader JsonReader

The reader positioned at the root document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

TProvider

The root type shape witness.

DeserializePath<TRoot, TElement, TProvider>(scoped in ReadOnlySequence<byte>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement, TProvider>(scoped in ReadOnlySequence<byte> utf8Json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TProvider : IShapeable<TRoot>

Parameters

utf8Json ReadOnlySequence<byte>

The possibly segmented UTF-8 document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

TProvider

The root type shape witness.

DeserializePath<TRoot, TElement, TProvider>(Stream, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement, TProvider>(Stream stream, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TProvider : IShapeable<TRoot>

Parameters

stream Stream

The document stream, which is read to its end and remains open.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

TProvider

The root type shape witness.

DeserializePath<TRoot, TElement, TProvider>(ReadOnlyMemory<byte>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement, TProvider>(ReadOnlyMemory<byte> utf8Json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TProvider : IShapeable<TRoot>

Parameters

utf8Json ReadOnlyMemory<byte>

The UTF-8 document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

TProvider

The root type shape witness.

DeserializePath<TRoot, TElement, TProvider>(string, in DeserializePathOptions<TRoot, TElement>, CancellationToken)

Deserializes a value selected by an expression, leaving the reader immediately after that value.

public TElement? DeserializePath<TRoot, TElement, TProvider>(string json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default) where TProvider : IShapeable<TRoot>

Parameters

json string

The JSON document.

options JsonSerializer.DeserializePathOptions<TRoot, TElement>

The selection options.

cancellationToken CancellationToken

A cancellation token.

Returns

TElement

The selected value.

Type Parameters

TRoot

The root document type.

TElement

The selected value type.

TProvider

The root type shape witness.

Deserialize<T>(ref JsonReader, ITypeShape<T>, SerializationContext)

Deserializes a value from JSON using the specified type shape and a caller-supplied starting context.

public T? Deserialize<T>(ref JsonReader reader, ITypeShape<T> shape, SerializationContext startingContext)

Parameters

reader JsonReader

The reader to deserialize the value from.

shape ITypeShape<T>

The type shape describing the structure of T.

startingContext SerializationContext

The context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.

Returns

T

The deserialized value, or null if the JSON represents a null value.

Type Parameters

T

The type of value to deserialize.

Remarks

Use this overload to supply per-call state to converters via this[object].

Exceptions

ArgumentException

Thrown if startingContext belongs to an operation already in progress.

Deserialize<T>(ref JsonReader, ITypeShape<T>, CancellationToken)

Deserializes a value from JSON using the specified type shape.

public T? Deserialize<T>(ref JsonReader reader, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

reader JsonReader

The reader to deserialize the value from.

shape ITypeShape<T>

The type shape describing the structure of T.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

T

The deserialized value, or null if the JSON represents a null value.

Type Parameters

T

The type of value to deserialize.

Deserialize<T>(ref JsonReader, CancellationToken)

Deserializes a value from JSON using the specified type shape.

[ExcludeFromCodeCoverage]
public T? Deserialize<T>(ref JsonReader reader, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

reader JsonReader

The reader to deserialize the value from.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

T

The deserialized value, or null if the JSON represents a null value.

Type Parameters

T

The type of value to deserialize.

Deserialize<T>(scoped in ReadOnlySequence<byte>, ITypeShape<T>, CancellationToken)

Deserializes a value from JSON using the specified type shape.

public T? Deserialize<T>(scoped in ReadOnlySequence<byte> buffer, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

buffer ReadOnlySequence<byte>

The UTF-8 JSON to deserialize from. Only the first value is deserialized.

shape ITypeShape<T>

The type shape describing the structure of T.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

T

The deserialized value, or null if the JSON represents a null value.

Type Parameters

T

The type of value to deserialize.

Deserialize<T>(scoped in ReadOnlySequence<byte>, CancellationToken)

Deserializes a value from JSON using the specified type shape.

[ExcludeFromCodeCoverage]
public T? Deserialize<T>(scoped in ReadOnlySequence<byte> bytes, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

bytes ReadOnlySequence<byte>
cancellationToken CancellationToken

A token to cancel the operation.

Returns

T

The deserialized value, or null if the JSON represents a null value.

Type Parameters

T

The type of value to deserialize.

Deserialize<T>(Stream, ITypeShape<T>, CancellationToken)

Deserializes the first UTF-8 JSON value from a stream.

public T? Deserialize<T>(Stream stream, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

stream Stream

The JSON stream.

shape ITypeShape<T>

The type shape describing T.

cancellationToken CancellationToken

A cancellation token.

Returns

T

The deserialized value.

Type Parameters

T

The type to deserialize.

Remarks

The stream is buffered to its end and left open. Use a caller-owned pipe for consecutive incremental reads.

Deserialize<T>(Stream, CancellationToken)

Deserializes the first UTF-8 JSON value from a stream.

[ExcludeFromCodeCoverage]
public T? Deserialize<T>(Stream stream, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

stream Stream

The JSON stream.

cancellationToken CancellationToken

A cancellation token.

Returns

T

The deserialized value.

Type Parameters

T

The type to deserialize.

Remarks

The stream is buffered to its end and left open. Use a caller-owned pipe for consecutive incremental reads.

Deserialize<T>(ReadOnlyMemory<byte>, ITypeShape<T>, CancellationToken)

Deserializes a value from JSON using the specified type shape.

public T? Deserialize<T>(ReadOnlyMemory<byte> buffer, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

buffer ReadOnlyMemory<byte>

The UTF-8 JSON to deserialize from. Only the first value is deserialized.

shape ITypeShape<T>

The type shape describing the structure of T.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

T

The deserialized value, or null if the JSON represents a null value.

Type Parameters

T

The type of value to deserialize.

Deserialize<T>(ReadOnlyMemory<byte>, CancellationToken)

Deserializes a value from JSON using the specified type shape.

[ExcludeFromCodeCoverage]
public T? Deserialize<T>(ReadOnlyMemory<byte> bytes, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

bytes ReadOnlyMemory<byte>
cancellationToken CancellationToken

A token to cancel the operation.

Returns

T

The deserialized value, or null if the JSON represents a null value.

Type Parameters

T

The type of value to deserialize.

Deserialize<T>(string, ITypeShape<T>, CancellationToken)

Deserializes JSON text.

public T? Deserialize<T>(string json, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

json string

The JSON text.

shape ITypeShape<T>

The type shape describing T.

cancellationToken CancellationToken

A cancellation token.

Returns

T

The deserialized value.

Type Parameters

T

The type to deserialize.

Deserialize<T>(string, CancellationToken)

Deserializes JSON text.

[ExcludeFromCodeCoverage]
public T? Deserialize<T>(string json, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

json string

The JSON text.

cancellationToken CancellationToken

A cancellation token.

Returns

T

The deserialized value.

Type Parameters

T

The type to deserialize.

Deserialize<T, TProvider>(ref JsonReader, CancellationToken)

Deserializes a value from JSON using the specified type shape.

[ExcludeFromCodeCoverage]
public T? Deserialize<T, TProvider>(ref JsonReader reader, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

reader JsonReader

The reader to deserialize the value from.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

T

The deserialized value, or null if the JSON represents a null value.

Type Parameters

T

The type of value to deserialize.

TProvider

Deserialize<T, TProvider>(scoped in ReadOnlySequence<byte>, CancellationToken)

Deserializes a value from JSON using the specified type shape.

[ExcludeFromCodeCoverage]
public T? Deserialize<T, TProvider>(scoped in ReadOnlySequence<byte> bytes, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

bytes ReadOnlySequence<byte>
cancellationToken CancellationToken

A token to cancel the operation.

Returns

T

The deserialized value, or null if the JSON represents a null value.

Type Parameters

T

The type of value to deserialize.

TProvider

Deserialize<T, TProvider>(Stream, CancellationToken)

Deserializes the first UTF-8 JSON value from a stream.

[ExcludeFromCodeCoverage]
public T? Deserialize<T, TProvider>(Stream stream, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

stream Stream

The JSON stream.

cancellationToken CancellationToken

A cancellation token.

Returns

T

The deserialized value.

Type Parameters

T

The type to deserialize.

TProvider

Remarks

The stream is buffered to its end and left open. Use a caller-owned pipe for consecutive incremental reads.

Deserialize<T, TProvider>(ReadOnlyMemory<byte>, CancellationToken)

Deserializes a value from JSON using the specified type shape.

[ExcludeFromCodeCoverage]
public T? Deserialize<T, TProvider>(ReadOnlyMemory<byte> bytes, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

bytes ReadOnlyMemory<byte>
cancellationToken CancellationToken

A token to cancel the operation.

Returns

T

The deserialized value, or null if the JSON represents a null value.

Type Parameters

T

The type of value to deserialize.

TProvider

Deserialize<T, TProvider>(string, CancellationToken)

Deserializes JSON text.

[ExcludeFromCodeCoverage]
public T? Deserialize<T, TProvider>(string json, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

json string

The JSON text.

cancellationToken CancellationToken

A cancellation token.

Returns

T

The deserialized value.

Type Parameters

T

The type to deserialize.

TProvider

GetJsonSchema(ITypeShape)

Produces a JSON Schema (draft 2020-12 by default) document that describes how this serializer represents the given type.

public JsonObject GetJsonSchema(ITypeShape typeShape)

Parameters

typeShape ITypeShape

The shape of the type.

Returns

JsonObject

The JSON Schema document as a JSON object.

Remarks

The schema reflects the effective configuration, including the property naming policy, enum-by-name serialization, reference preservation, and runtime union configuration. Custom converters that do not override GetJsonSchema(JsonSchemaContext, ITypeShape) produce a permissive schema annotated with a conspicuous comment rather than false precision.

GetJsonSchema(ITypeShape, JsonSchemaOptions)

Produces a JSON Schema document that describes how this serializer represents the given type.

public JsonObject GetJsonSchema(ITypeShape typeShape, JsonSchemaOptions options)

Parameters

typeShape ITypeShape

The shape of the type.

options JsonSchemaOptions

The schema generation options.

Returns

JsonObject

The JSON Schema document as a JSON object.

Exceptions

ArgumentOutOfRangeException

The requested dialect is not supported.

GetJsonSchema<T>()

Produces a JSON Schema (draft 2020-12 by default) document that describes how this serializer represents the given type.

public JsonObject GetJsonSchema<T>() where T : IShapeable<T>

Returns

JsonObject

The JSON Schema document as a JSON object.

Type Parameters

T

The type to describe.

Remarks

The schema reflects the effective configuration, including the property naming policy, enum-by-name serialization, reference preservation, and runtime union configuration. Custom converters that do not override GetJsonSchema(JsonSchemaContext, ITypeShape) produce a permissive schema annotated with a conspicuous comment rather than false precision.

GetJsonSchema<T>(JsonSchemaOptions)

Produces a JSON Schema document using the specified options.

public JsonObject GetJsonSchema<T>(JsonSchemaOptions options) where T : IShapeable<T>

Parameters

options JsonSchemaOptions

The schema generation options.

Returns

JsonObject

The JSON Schema document as a JSON object.

Type Parameters

T

The type to describe.

GetJsonSchema<T>(ITypeShapeProvider)

Produces a JSON Schema using a type shape provider.

[SuppressMessage("ApiDesign", "RS0030:Do not use banned APIs", Justification = "Public API accepts an ITypeShapeProvider.")]
public JsonObject GetJsonSchema<T>(ITypeShapeProvider provider)

Parameters

provider ITypeShapeProvider

The type shape provider.

Returns

JsonObject

The JSON Schema document.

Type Parameters

T

The type to describe.

GetJsonSchema<T>(ITypeShapeProvider, JsonSchemaOptions)

Produces a JSON Schema using a type shape provider and specified options.

[SuppressMessage("ApiDesign", "RS0030:Do not use banned APIs", Justification = "Public API accepts an ITypeShapeProvider.")]
public JsonObject GetJsonSchema<T>(ITypeShapeProvider provider, JsonSchemaOptions options)

Parameters

provider ITypeShapeProvider

The type shape provider.

options JsonSchemaOptions

The schema generation options.

Returns

JsonObject

The JSON Schema document.

Type Parameters

T

The type to describe.

Exceptions

ArgumentException

The provider does not supply the requested type shape.

GetJsonSchema<T>(ITypeShape<T>)

Produces a JSON Schema (draft 2020-12 by default) document that describes how this serializer represents the given type.

public JsonObject GetJsonSchema<T>(ITypeShape<T> shape)

Parameters

shape ITypeShape<T>

The shape of the type.

Returns

JsonObject

The JSON Schema document as a JSON object.

Type Parameters

T

The type to describe.

Remarks

The schema reflects the effective configuration, including the property naming policy, enum-by-name serialization, reference preservation, and runtime union configuration. Custom converters that do not override GetJsonSchema(JsonSchemaContext, ITypeShape) produce a permissive schema annotated with a conspicuous comment rather than false precision.

GetJsonSchema<T>(ITypeShape<T>, JsonSchemaOptions)

Produces a JSON Schema document that describes how this serializer represents the given type.

public JsonObject GetJsonSchema<T>(ITypeShape<T> shape, JsonSchemaOptions options)

Parameters

shape ITypeShape<T>

The shape of the type.

options JsonSchemaOptions

The schema generation options.

Returns

JsonObject

The JSON Schema document as a JSON object.

Type Parameters

T

The type to describe.

Exceptions

ArgumentOutOfRangeException

The requested dialect is not supported.

GetJsonSchema<T, TProvider>()

Produces a JSON Schema document that describes how this serializer represents T, using a witness type for the shape.

public JsonObject GetJsonSchema<T, TProvider>() where TProvider : IShapeable<T>

Returns

JsonObject

The JSON Schema document as a JSON object.

Type Parameters

T

The type to describe.

TProvider

A witness type that provides the shape for T.

GetJsonSchema<T, TProvider>(JsonSchemaOptions)

Produces a JSON Schema document using the specified options and witness type.

public JsonObject GetJsonSchema<T, TProvider>(JsonSchemaOptions options) where TProvider : IShapeable<T>

Parameters

options JsonSchemaOptions

The schema generation options.

Returns

JsonObject

The JSON Schema document as a JSON object.

Type Parameters

T

The type to describe.

TProvider

A witness type that provides the shape for T.

SerializeArrayAsync<T>(PipeWriter, IAsyncEnumerable<T>, ITypeShape<T>, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> as a top-level JSON array, writing elements as they are produced with bounded memory and backpressure.

public ValueTask SerializeArrayAsync<T>(PipeWriter writer, IAsyncEnumerable<T> values, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

values IAsyncEnumerable<T>

The asynchronous source of elements.

shape ITypeShape<T>

The shape of T.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The element type.

SerializeArrayAsync<T>(PipeWriter, IAsyncEnumerable<T>, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> as a top-level JSON array, writing elements as they are produced with bounded memory and backpressure.

public ValueTask SerializeArrayAsync<T>(PipeWriter writer, IAsyncEnumerable<T> values, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

values IAsyncEnumerable<T>

The asynchronous source of elements.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The element type.

SerializeArrayAsync<T>(Stream, IAsyncEnumerable<T>, ITypeShape<T>, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> as a top-level JSON array to a stream.

public ValueTask SerializeArrayAsync<T>(Stream stream, IAsyncEnumerable<T> values, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream to write to. It is flushed but not disposed or closed by this method.

values IAsyncEnumerable<T>

The asynchronous source of elements.

shape ITypeShape<T>

The shape of T.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The element type.

SerializeArrayAsync<T>(Stream, IAsyncEnumerable<T>, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> as a top-level JSON array to a stream.

public ValueTask SerializeArrayAsync<T>(Stream stream, IAsyncEnumerable<T> values, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

stream Stream

The stream to write to. It is flushed but not disposed or closed by this method.

values IAsyncEnumerable<T>

The asynchronous source of elements.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The element type.

SerializeAsync<T>(PipeWriter, T?, SerializationContext)

Serializes a value as UTF-8 JSON to a PipeWriter incrementally using a caller-supplied starting context, flushing periodically so large graphs are written with bounded memory and backpressure.

public ValueTask SerializeAsync<T>(PipeWriter writer, T? value, SerializationContext startingContext) where T : IShapeable<T>

Parameters

writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

value T

The value to serialize.

startingContext SerializationContext

The context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.

Returns

ValueTask

A task tracking the asynchronous serialization.

Type Parameters

T

The type of value to serialize.

Remarks

Use this overload to supply per-call state to converters via this[object].

Exceptions

ArgumentException

Thrown if startingContext belongs to an operation already in progress.

SerializeAsync<T>(PipeWriter, T?, ITypeShape<T>, SerializationContext)

Serializes a value as UTF-8 JSON to a PipeWriter incrementally using a caller-supplied starting context, flushing periodically so large graphs are written with bounded memory and backpressure.

public ValueTask SerializeAsync<T>(PipeWriter writer, T? value, ITypeShape<T> shape, SerializationContext startingContext)

Parameters

writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

value T

The value to serialize.

shape ITypeShape<T>

The type shape describing T.

startingContext SerializationContext

The context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.

Returns

ValueTask

A task tracking the asynchronous serialization.

Type Parameters

T

The type of value to serialize.

Remarks

Use this overload to supply per-call state to converters via this[object].

Exceptions

ArgumentException

Thrown if startingContext belongs to an operation already in progress.

SerializeAsync<T>(PipeWriter, T?, ITypeShape<T>, CancellationToken)

Serializes a value as UTF-8 JSON to a PipeWriter incrementally, flushing periodically so large graphs are written with bounded memory and backpressure.

public ValueTask SerializeAsync<T>(PipeWriter writer, T? value, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

value T

The value to serialize.

shape ITypeShape<T>

The type shape describing T.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the asynchronous serialization.

Type Parameters

T

The type of value to serialize.

SerializeAsync<T>(PipeWriter, T?, CancellationToken)

Serializes a value as UTF-8 JSON to a PipeWriter incrementally, flushing periodically so large graphs are written with bounded memory and backpressure.

public ValueTask SerializeAsync<T>(PipeWriter writer, T? value, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

value T

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the asynchronous serialization.

Type Parameters

T

The type of value to serialize.

SerializeAsync<T>(Stream, T?, SerializationContext)

Serializes a value asynchronously to a stream with per-call state.

public ValueTask SerializeAsync<T>(Stream stream, T? value, SerializationContext startingContext) where T : IShapeable<T>

Parameters

stream Stream

The destination stream, which is left open.

value T

The value to serialize.

startingContext SerializationContext

The inactive starting context.

Returns

ValueTask

A task tracking the write.

Type Parameters

T

The type of value.

SerializeAsync<T>(Stream, T?, ITypeShape<T>, SerializationContext)

Serializes a value asynchronously to a stream with per-call state.

public ValueTask SerializeAsync<T>(Stream stream, T? value, ITypeShape<T> shape, SerializationContext startingContext)

Parameters

stream Stream

The destination stream, which is left open.

value T

The value to serialize.

shape ITypeShape<T>

The shape describing the value.

startingContext SerializationContext

The inactive starting context.

Returns

ValueTask

A task tracking the write.

Type Parameters

T

The type of value.

SerializeAsync<T>(Stream, T?, ITypeShape<T>, CancellationToken)

Serializes a value as UTF-8 JSON to a Stream incrementally.

public ValueTask SerializeAsync<T>(Stream stream, T? value, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

stream Stream

The destination stream. It is flushed but not disposed or closed by this method.

value T

The value to serialize.

shape ITypeShape<T>

The type shape describing T.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the asynchronous serialization.

Type Parameters

T

The type of value to serialize.

SerializeAsync<T>(Stream, T?, CancellationToken)

Serializes a value as UTF-8 JSON to a Stream incrementally.

public ValueTask SerializeAsync<T>(Stream stream, T? value, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

stream Stream

The destination stream. It is flushed but not disposed or closed by this method.

value T

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the asynchronous serialization.

Type Parameters

T

The type of value to serialize.

SerializeAsync<T, TProvider>(PipeWriter, T?, SerializationContext)

Serializes a value as UTF-8 JSON to a PipeWriter incrementally using a caller-supplied starting context, flushing periodically so large graphs are written with bounded memory and backpressure.

public ValueTask SerializeAsync<T, TProvider>(PipeWriter writer, T? value, SerializationContext startingContext) where TProvider : IShapeable<T>

Parameters

writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

value T

The value to serialize.

startingContext SerializationContext

The context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.

Returns

ValueTask

A task tracking the asynchronous serialization.

Type Parameters

T

The type of value to serialize.

TProvider

Remarks

Use this overload to supply per-call state to converters via this[object].

Exceptions

ArgumentException

Thrown if startingContext belongs to an operation already in progress.

SerializeAsync<T, TProvider>(PipeWriter, T?, CancellationToken)

Serializes a value as UTF-8 JSON to a PipeWriter incrementally, flushing periodically so large graphs are written with bounded memory and backpressure.

public ValueTask SerializeAsync<T, TProvider>(PipeWriter writer, T? value, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

value T

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the asynchronous serialization.

Type Parameters

T

The type of value to serialize.

TProvider

SerializeAsync<T, TProvider>(Stream, T?, SerializationContext)

Serializes a value asynchronously to a stream with per-call state.

public ValueTask SerializeAsync<T, TProvider>(Stream stream, T? value, SerializationContext startingContext) where TProvider : IShapeable<T>

Parameters

stream Stream

The destination stream, which is left open.

value T

The value to serialize.

startingContext SerializationContext

The inactive starting context.

Returns

ValueTask

A task tracking the write.

Type Parameters

T

The type of value.

TProvider

SerializeAsync<T, TProvider>(Stream, T?, CancellationToken)

Serializes a value as UTF-8 JSON to a Stream incrementally.

public ValueTask SerializeAsync<T, TProvider>(Stream stream, T? value, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

stream Stream

The destination stream. It is flushed but not disposed or closed by this method.

value T

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the asynchronous serialization.

Type Parameters

T

The type of value to serialize.

TProvider

SerializeEnumerableAsync<T>(PipeWriter, IAsyncEnumerable<T>, SequenceOptions, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> using the selected JSON framing.

public ValueTask SerializeEnumerableAsync<T>(PipeWriter writer, IAsyncEnumerable<T> values, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

values IAsyncEnumerable<T>

The asynchronous source of values.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The value type.

SerializeEnumerableAsync<T>(PipeWriter, IAsyncEnumerable<T>, ITypeShape<T>, SequenceOptions, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> using the selected JSON framing.

public ValueTask SerializeEnumerableAsync<T>(PipeWriter writer, IAsyncEnumerable<T> values, ITypeShape<T> shape, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)

Parameters

writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

values IAsyncEnumerable<T>

The asynchronous source of values.

shape ITypeShape<T>

The shape of T.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The value type.

SerializeEnumerableAsync<T>(Stream, IAsyncEnumerable<T>, SequenceOptions, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> to a stream using the selected JSON framing.

public ValueTask SerializeEnumerableAsync<T>(Stream stream, IAsyncEnumerable<T> values, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

stream Stream

The stream to write to. It is flushed but not disposed or closed by this method.

values IAsyncEnumerable<T>

The asynchronous source of values.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The value type.

SerializeEnumerableAsync<T>(Stream, IAsyncEnumerable<T>, ITypeShape<T>, SequenceOptions, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> to a stream using the selected JSON framing.

public ValueTask SerializeEnumerableAsync<T>(Stream stream, IAsyncEnumerable<T> values, ITypeShape<T> shape, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream to write to. It is flushed but not disposed or closed by this method.

values IAsyncEnumerable<T>

The asynchronous source of values.

shape ITypeShape<T>

The shape of T.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The value type.

SerializeEnumerableAsync<T, TProvider>(PipeWriter, IAsyncEnumerable<T>, SequenceOptions, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> using the selected JSON framing.

public ValueTask SerializeEnumerableAsync<T, TProvider>(PipeWriter writer, IAsyncEnumerable<T> values, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

writer PipeWriter

The pipe to write to. It is flushed but never completed by this method.

values IAsyncEnumerable<T>

The asynchronous source of values.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The value type.

TProvider

SerializeEnumerableAsync<T, TProvider>(Stream, IAsyncEnumerable<T>, SequenceOptions, CancellationToken)

Asynchronously serializes an IAsyncEnumerable<T> to a stream using the selected JSON framing.

public ValueTask SerializeEnumerableAsync<T, TProvider>(Stream stream, IAsyncEnumerable<T> values, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

stream Stream

The stream to write to. It is flushed but not disposed or closed by this method.

values IAsyncEnumerable<T>

The asynchronous source of values.

options JsonSerializer.SequenceOptions

The framing options. The default is newline-delimited JSON.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

Type Parameters

T

The value type.

TProvider

SerializeJsonValue(JsonValue?, CancellationToken)

Serializes a JsonValue to JSON text.

public string SerializeJsonValue(JsonValue? value, CancellationToken cancellationToken = default)

Parameters

value JsonValue

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Returns

string

The serialized JSON text.

SerializeJsonValue(IBufferWriter<byte>, JsonValue?, CancellationToken)

Serializes a JsonValue as UTF-8 JSON to a buffer.

public void SerializeJsonValue(IBufferWriter<byte> writer, JsonValue? value, CancellationToken cancellationToken = default)

Parameters

writer IBufferWriter<byte>

The destination buffer.

value JsonValue

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

SerializeJsonValue(Stream, JsonValue?, CancellationToken)

Serializes a JsonValue as UTF-8 JSON to a stream.

public void SerializeJsonValue(Stream stream, JsonValue? value, CancellationToken cancellationToken = default)

Parameters

stream Stream

The destination stream. It is flushed but not disposed by this method.

value JsonValue

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

SerializeJsonValueAsync(PipeWriter, JsonValue?, CancellationToken)

Serializes a JsonValue as UTF-8 JSON to a PipeWriter incrementally.

public ValueTask SerializeJsonValueAsync(PipeWriter writer, JsonValue? value, CancellationToken cancellationToken = default)

Parameters

writer PipeWriter

The pipe. It is flushed but not completed by this method.

value JsonValue

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the serialization.

SerializeJsonValueAsync(Stream, JsonValue?, CancellationToken)

Serializes a JsonValue document object model to a Stream.

public ValueTask SerializeJsonValueAsync(Stream stream, JsonValue? value, CancellationToken cancellationToken = default)

Parameters

stream Stream

The destination stream. It is flushed but not disposed by this method.

value JsonValue

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task that completes when serialization finishes.

SerializeObject(ref JsonWriter, object?, ITypeShape, SerializationContext)

Serializes an untyped value to JSON using the specified type shape and a caller-supplied starting context.

public void SerializeObject(ref JsonWriter writer, object? value, ITypeShape shape, SerializationContext startingContext)

Parameters

writer JsonWriter

The writer to serialize the value into.

value object

The value to serialize.

shape ITypeShape

The type shape describing the structure of value.

startingContext SerializationContext

The context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.

Exceptions

ArgumentException

Thrown if startingContext belongs to an operation already in progress.

SerializeObject(ref JsonWriter, object?, ITypeShape, CancellationToken)

Serializes an untyped value to JSON using the specified type shape.

public void SerializeObject(ref JsonWriter writer, object? value, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

writer JsonWriter

The writer to serialize the value into.

value object

The value to serialize.

shape ITypeShape

The type shape describing the structure of value.

cancellationToken CancellationToken

A token to cancel the operation.

SerializeObject(IBufferWriter<byte>, object?, ITypeShape, CancellationToken)

Serializes an untyped value to JSON using the specified type shape.

public void SerializeObject(IBufferWriter<byte> writer, object? value, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

writer IBufferWriter<byte>

The writer to serialize the value into.

value object

The value to serialize.

shape ITypeShape

The type shape describing the structure of value.

cancellationToken CancellationToken

A token to cancel the operation.

SerializeObject(Stream, object?, ITypeShape, CancellationToken)

Serializes an untyped value to JSON using the specified type shape.

public void SerializeObject(Stream stream, object? value, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

stream Stream

The destination stream.

value object

The value to serialize.

shape ITypeShape

The type shape describing the structure of value.

cancellationToken CancellationToken

A token to cancel the operation.

SerializeObject(object?, ITypeShape, CancellationToken)

Serializes an untyped value to JSON using the specified type shape.

public string SerializeObject(object? value, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

value object

The value to serialize.

shape ITypeShape

The type shape describing the structure of value.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

string

The serialized JSON text.

SerializeObjectAsync(PipeWriter, object?, ITypeShape, SerializationContext)

Serializes an untyped value asynchronously to a pipe using per-call state.

public ValueTask SerializeObjectAsync(PipeWriter writer, object? value, ITypeShape shape, SerializationContext startingContext)

Parameters

writer PipeWriter

The destination pipe, which is not completed.

value object

The value to serialize.

shape ITypeShape

The shape describing the value.

startingContext SerializationContext

The inactive starting context for this operation.

Returns

ValueTask

A task tracking the write.

SerializeObjectAsync(PipeWriter, object?, ITypeShape, CancellationToken)

Serializes an untyped value asynchronously to a pipe.

public ValueTask SerializeObjectAsync(PipeWriter writer, object? value, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

writer PipeWriter

The destination pipe, which is not completed.

value object

The value to serialize.

shape ITypeShape

The shape describing the value.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the write.

SerializeObjectAsync(Stream, object?, ITypeShape, SerializationContext)

Serializes an untyped value asynchronously to a stream using per-call state.

public ValueTask SerializeObjectAsync(Stream stream, object? value, ITypeShape shape, SerializationContext startingContext)

Parameters

stream Stream

The destination stream, which is left open.

value object

The value to serialize.

shape ITypeShape

The shape describing the value.

startingContext SerializationContext

The inactive starting context for this operation.

Returns

ValueTask

A task tracking the write.

SerializeObjectAsync(Stream, object?, ITypeShape, CancellationToken)

Serializes an untyped value asynchronously to a stream.

public ValueTask SerializeObjectAsync(Stream stream, object? value, ITypeShape shape, CancellationToken cancellationToken = default)

Parameters

stream Stream

The destination stream, which is left open.

value object

The value to serialize.

shape ITypeShape

The shape describing the value.

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A task tracking the write.

Serialize<T>(ref JsonWriter, in T?, ITypeShape<T>, SerializationContext)

Serializes a value to JSON using the specified type shape and a caller-supplied starting context.

public void Serialize<T>(ref JsonWriter writer, in T? value, ITypeShape<T> shape, SerializationContext startingContext)

Parameters

writer JsonWriter

The writer to serialize the value into.

value T

The value to serialize.

shape ITypeShape<T>

The type shape describing the structure of T.

startingContext SerializationContext

The context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.

Type Parameters

T

The type of value to serialize.

Remarks

Use this overload to supply per-call state to converters via this[object].

Exceptions

ArgumentException

Thrown if startingContext belongs to an operation already in progress.

Serialize<T>(ref JsonWriter, in T?, ITypeShape<T>, CancellationToken)

Serializes a value to JSON using the specified type shape.

public void Serialize<T>(ref JsonWriter writer, in T? value, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

writer JsonWriter

The writer to serialize the value into.

value T

The value to serialize.

shape ITypeShape<T>

The type shape describing the structure of T.

cancellationToken CancellationToken

A token to cancel the operation.

Type Parameters

T

The type of value to serialize.

Serialize<T>(ref JsonWriter, in T?, CancellationToken)

Serializes a value to JSON using the specified type shape.

[ExcludeFromCodeCoverage]
public void Serialize<T>(ref JsonWriter writer, in T? value, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

writer JsonWriter

The writer to serialize the value into.

value T

The value to serialize.

cancellationToken CancellationToken

A token to cancel the operation.

Type Parameters

T

The type of value to serialize.

Serialize<T>(IBufferWriter<byte>, in T?, ITypeShape<T>, CancellationToken)

Serializes a value as UTF-8 JSON to a byte buffer.

public void Serialize<T>(IBufferWriter<byte> writer, in T? value, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

writer IBufferWriter<byte>

The destination buffer.

value T

The value to serialize.

shape ITypeShape<T>

The type shape describing T.

cancellationToken CancellationToken

A cancellation token.

Type Parameters

T

The type of value to serialize.

Serialize<T>(IBufferWriter<byte>, in T?, CancellationToken)

Serializes a value as UTF-8 JSON to a byte buffer.

[ExcludeFromCodeCoverage]
public void Serialize<T>(IBufferWriter<byte> writer, in T? value, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

writer IBufferWriter<byte>

The destination buffer.

value T

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Type Parameters

T

The type of value to serialize.

Serialize<T>(Stream, in T?, ITypeShape<T>, CancellationToken)

Serializes a value as UTF-8 JSON to a stream.

public void Serialize<T>(Stream stream, in T? value, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

stream Stream

The destination stream.

value T

The value to serialize.

shape ITypeShape<T>

The type shape describing T.

cancellationToken CancellationToken

A cancellation token.

Type Parameters

T

The type of value to serialize.

Serialize<T>(Stream, in T?, CancellationToken)

Serializes a value as UTF-8 JSON to a stream.

[ExcludeFromCodeCoverage]
public void Serialize<T>(Stream stream, in T? value, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

stream Stream

The destination stream.

value T

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Type Parameters

T

The type of value to serialize.

Serialize<T>(in T?, ITypeShape<T>, CancellationToken)

Serializes a value to JSON text.

public string Serialize<T>(in T? value, ITypeShape<T> shape, CancellationToken cancellationToken = default)

Parameters

value T

The value to serialize.

shape ITypeShape<T>

The type shape describing T.

cancellationToken CancellationToken

A cancellation token.

Returns

string

The serialized JSON text.

Type Parameters

T

The type of value to serialize.

Serialize<T>(in T?, CancellationToken)

Serializes a value to JSON text.

[ExcludeFromCodeCoverage]
public string Serialize<T>(in T? value, CancellationToken cancellationToken = default) where T : IShapeable<T>

Parameters

value T

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Returns

string

The serialized JSON text.

Type Parameters

T

The type of value to serialize.

Serialize<T, TProvider>(ref JsonWriter, in T?, CancellationToken)

Serializes a value to JSON using the specified type shape.

[ExcludeFromCodeCoverage]
public void Serialize<T, TProvider>(ref JsonWriter writer, in T? value, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

writer JsonWriter

The writer to serialize the value into.

value T

The value to serialize.

cancellationToken CancellationToken

A token to cancel the operation.

Type Parameters

T

The type of value to serialize.

TProvider

Serialize<T, TProvider>(IBufferWriter<byte>, in T?, CancellationToken)

Serializes a value as UTF-8 JSON to a byte buffer.

[ExcludeFromCodeCoverage]
public void Serialize<T, TProvider>(IBufferWriter<byte> writer, in T? value, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

writer IBufferWriter<byte>

The destination buffer.

value T

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Type Parameters

T

The type of value to serialize.

TProvider

Serialize<T, TProvider>(Stream, in T?, CancellationToken)

Serializes a value as UTF-8 JSON to a stream.

[ExcludeFromCodeCoverage]
public void Serialize<T, TProvider>(Stream stream, in T? value, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

stream Stream

The destination stream.

value T

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Type Parameters

T

The type of value to serialize.

TProvider

Serialize<T, TProvider>(in T?, CancellationToken)

Serializes a value to JSON text.

[ExcludeFromCodeCoverage]
public string Serialize<T, TProvider>(in T? value, CancellationToken cancellationToken = default) where TProvider : IShapeable<T>

Parameters

value T

The value to serialize.

cancellationToken CancellationToken

A cancellation token.

Returns

string

The serialized JSON text.

Type Parameters

T

The type of value to serialize.

TProvider