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
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
ConverterTypes
Gets the runtime-registered converter types that take precedence after Nerdbank.Json.JsonSerializerConfiguration.Converters.
public ConverterTypeCollection ConverterTypes { get; init; }
Property Value
Converters
Gets the runtime-registered converters that take precedence over built-in and shape-based converters.
public ConverterCollection Converters { get; init; }
Property Value
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
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
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
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
PropertyNameCaseInsensitive
Gets a value indicating whether JSON object property names are matched case-insensitively during deserialization.
public bool PropertyNameCaseInsensitive { get; init; }
Property Value
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
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
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
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
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
UnionTypeAliasProvider
Gets the optional provider of custom C# union case identifiers.
public IUnionTypeAliasProvider? UnionTypeAliasProvider { get; init; }
Property Value
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
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
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
providerITypeShapeProviderThe shape provider for the operation.
cancellationTokenCancellationTokenA 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
shapeITypeShape<T>The shape of
T.cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<T>
An asynchronous sequence of elements.
Type Parameters
TThe 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<T>
An asynchronous sequence of elements.
Type Parameters
TThe 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
streamStreamThe stream to read from. It is read but not disposed or closed by this method.
shapeITypeShape<T>The shape of
T.cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<T>
An asynchronous sequence of elements.
Type Parameters
TThe 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
streamStreamThe stream to read from. It is read but not disposed or closed by this method.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<T>
An asynchronous sequence of elements.
Type Parameters
TThe 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
startingContextSerializationContextThe 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
TThe type to deserialize.
Remarks
Use this overload to supply per-call state to converters via this[object].
Exceptions
- ArgumentException
Thrown if
startingContextbelongs 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
shapeITypeShape<T>The type shape describing
T.startingContextSerializationContextThe 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
TThe type to deserialize.
Remarks
Use this overload to supply per-call state to converters via this[object].
Exceptions
- ArgumentException
Thrown if
startingContextbelongs 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
shapeITypeShape<T>The type shape describing
T.cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask<T>
A task whose result is the deserialized value.
Type Parameters
TThe 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask<T>
A task whose result is the deserialized value.
Type Parameters
TThe 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
streamStreamThe source stream, which is left open.
startingContextSerializationContextThe inactive starting context.
Returns
- ValueTask<T>
The deserialized value.
Type Parameters
TThe 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
streamStreamThe source stream, which is left open.
shapeITypeShape<T>The shape describing the value.
startingContextSerializationContextThe inactive starting context.
Returns
- ValueTask<T>
The deserialized value.
Type Parameters
TThe 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
streamStreamThe source stream. It is read but not disposed or closed by this method.
shapeITypeShape<T>The type shape describing
T.cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask<T>
A task whose result is the deserialized value.
Type Parameters
TThe 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
streamStreamThe source stream. It is read but not disposed or closed by this method.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask<T>
A task whose result is the deserialized value.
Type Parameters
TThe 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
startingContextSerializationContextThe 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
TThe type to deserialize.
TProvider
Remarks
Use this overload to supply per-call state to converters via this[object].
Exceptions
- ArgumentException
Thrown if
startingContextbelongs 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask<T>
A task whose result is the deserialized value.
Type Parameters
TThe 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
streamStreamThe source stream, which is left open.
startingContextSerializationContextThe inactive starting context.
Returns
- ValueTask<T>
The deserialized value.
Type Parameters
TThe 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
streamStreamThe source stream. It is read but not disposed or closed by this method.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask<T>
A task whose result is the deserialized value.
Type Parameters
TThe 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
optionsJsonSerializer.SequenceOptionsThe framing options. The default is newline-delimited JSON.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<T>
An asynchronous sequence of values.
Type Parameters
TThe 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
shapeITypeShape<T>The shape of
T.optionsJsonSerializer.SequenceOptionsThe framing options. The default is newline-delimited JSON.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<T>
An asynchronous sequence of values.
Type Parameters
TThe 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
streamStreamThe stream to read from. It is read but not disposed or closed by this method.
optionsJsonSerializer.SequenceOptionsThe framing options. The default is newline-delimited JSON.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<T>
An asynchronous sequence of values.
Type Parameters
TThe 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
streamStreamThe stream to read from. It is read but not disposed or closed by this method.
shapeITypeShape<T>The shape of
T.optionsJsonSerializer.SequenceOptionsThe framing options. The default is newline-delimited JSON.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<T>
An asynchronous sequence of values.
Type Parameters
TThe 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
optionsJsonSerializer.SequenceOptionsThe framing options. The default is newline-delimited JSON.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<T>
An asynchronous sequence of values.
Type Parameters
TThe 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
streamStreamThe stream to read from. It is read but not disposed or closed by this method.
optionsJsonSerializer.SequenceOptionsThe framing options. The default is newline-delimited JSON.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<T>
An asynchronous sequence of values.
Type Parameters
TThe 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
utf8JsonReadOnlySequence<byte>The UTF-8 JSON bytes, possibly spanning multiple segments.
cancellationTokenCancellationTokenA 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
streamStreamThe stream. It is read but not disposed by this method.
cancellationTokenCancellationTokenA 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
utf8JsonReadOnlyMemory<byte>The UTF-8 JSON bytes.
cancellationTokenCancellationTokenA 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
jsonstringThe JSON text.
cancellationTokenCancellationTokenA 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
readerPipeReaderThe pipe. It is advanced but not completed by this method.
cancellationTokenCancellationTokenA cancellation token.
Returns
Remarks
Unread bytes remain in the pipe for the caller.
DeserializeJsonValueAsync(Stream, CancellationToken)
public ValueTask<JsonValue?> DeserializeJsonValueAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
streamStreamThe stream. It is read but not disposed by this method.
cancellationTokenCancellationTokenA cancellation token.
Returns
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
readerJsonReaderThe reader to deserialize the value from.
shapeITypeShapeThe type shape describing the structure of the value to deserialize.
startingContextSerializationContextThe context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.
Returns
Exceptions
- ArgumentException
Thrown if
startingContextbelongs 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
readerJsonReaderThe reader to deserialize the value from.
shapeITypeShapeThe type shape describing the structure of the value to deserialize.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
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
bufferReadOnlySequence<byte>The JSON to deserialize from.
shapeITypeShapeThe type shape describing the structure of the value to deserialize.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
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
streamStreamThe JSON stream.
shapeITypeShapeThe type shape describing the structure of the value to deserialize.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
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
bufferReadOnlyMemory<byte>shapeITypeShapeThe type shape describing the structure of the value to deserialize.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
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
jsonstringshapeITypeShapeThe type shape describing the structure of the value to deserialize.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
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
readerPipeReaderThe source pipe, which is not completed.
shapeITypeShapeThe shape describing the value.
startingContextSerializationContextThe inactive starting context for this operation.
Returns
DeserializeObjectAsync(PipeReader, ITypeShape, CancellationToken)
Deserializes an untyped value asynchronously from a pipe.
public ValueTask<object?> DeserializeObjectAsync(PipeReader reader, ITypeShape shape, CancellationToken cancellationToken = default)
Parameters
readerPipeReaderThe source pipe, which is not completed.
shapeITypeShapeThe shape describing the value.
cancellationTokenCancellationTokenA cancellation token.
Returns
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
streamStreamThe source stream, which is left open.
shapeITypeShapeThe shape describing the value.
startingContextSerializationContextThe inactive starting context for this operation.
Returns
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
streamStreamThe source stream, which is left open.
shapeITypeShapeThe shape describing the value.
cancellationTokenCancellationTokenA cancellation token.
Returns
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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
pathJsonPathThe pre-parsed path that selects the array. Names are the serialized (wire) names.
missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<TElement>
An asynchronous sequence of elements.
Type Parameters
TElementThe 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
pathJsonPathThe pre-parsed path that selects the array. Names are the serialized (wire) names.
elementShapeITypeShape<TElement>The shape of
TElement.missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<TElement>
An asynchronous sequence of elements.
Type Parameters
TElementThe 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
streamStreamThe stream to read from. It is read but not disposed or closed by this method.
pathJsonPathThe pre-parsed path that selects the array.
missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<TElement>
An asynchronous sequence of elements.
Type Parameters
TElementThe 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
streamStreamThe stream to read from. It is read but not disposed or closed by this method.
pathJsonPathThe pre-parsed path that selects the array.
elementShapeITypeShape<TElement>The shape of
TElement.missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<TElement>
An asynchronous sequence of elements.
Type Parameters
TElementThe 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
readerPipeReaderThe pipe to read from. It is advanced but never completed by this method.
pathJsonPathThe pre-parsed path that selects the array. Names are the serialized (wire) names.
missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<TElement>
An asynchronous sequence of elements.
Type Parameters
TElementThe 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
readerPipeReaderThe input pipe.
optionscontrols whether it is completed.optionsJsonSerializer.StreamingEnumerationOptions<TRoot, TElement>The path, missing-path behavior, and pipe ownership options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<TElement>
The selected array elements.
Type Parameters
TRootThe root document type, which supplies its shape.
TElementThe 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
readerPipeReaderThe input pipe. Ownership is controlled by
options.shapeITypeShape<TRoot>The root type shape.
optionsJsonSerializer.StreamingEnumerationOptions<TRoot, TElement>The path and enumeration options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<TElement>
The selected array elements.
Type Parameters
TRootThe root document type.
TElementThe 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
streamStreamThe stream to read from. It is read but not disposed or closed by this method.
pathJsonPathThe pre-parsed path that selects the array.
missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<TElement>
An asynchronous sequence of elements.
Type Parameters
TElementThe 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
streamStreamThe input stream, which remains open.
optionsJsonSerializer.StreamingEnumerationOptions<TRoot, TElement>The path and enumeration options. The internally created pipe is always completed.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<TElement>
The selected array elements.
Type Parameters
TRootThe root document type, which supplies its shape.
TElementThe 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
streamStreamThe input stream, which remains open.
shapeITypeShape<TRoot>The root type shape.
optionsJsonSerializer.StreamingEnumerationOptions<TRoot, TElement>The path and enumeration options. The internally created pipe is always completed.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<TElement>
The selected array elements.
Type Parameters
TRootThe root document type.
TElementThe 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
readerPipeReaderThe input pipe.
optionscontrols whether it is completed.optionsJsonSerializer.StreamingEnumerationOptions<TRoot, TElement>The path, missing-path behavior, and pipe ownership options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<TElement>
The selected array elements.
Type Parameters
TRootThe root document type.
TElementThe selected array element type.
TProviderThe 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
streamStreamThe input stream, which remains open.
optionsJsonSerializer.StreamingEnumerationOptions<TRoot, TElement>The path and enumeration options. The internally created pipe is always completed.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<TElement>
The selected array elements.
Type Parameters
TRootThe root document type.
TElementThe selected array element type.
TProviderThe 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
readerJsonReaderThe reader positioned at the document.
pathJsonPathThe raw path to select.
missingBehaviorMissingPathBehaviorThe behavior for a missing path.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The selected value.
Type Parameters
TValueThe 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
readerJsonReaderThe reader positioned at the document.
pathJsonPathThe raw path to select.
targetShapeITypeShape<TValue>The selected value shape.
missingBehaviorMissingPathBehaviorThe behavior for a missing path.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The selected value.
Type Parameters
TValueThe 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
utf8JsonReadOnlySequence<byte>The UTF-8 JSON document, possibly spanning multiple buffer segments.
pathJsonPathThe pre-parsed path that selects the value.
missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The deserialized value, or the default value when the path is missing and default behavior is selected.
Type Parameters
TValueThe 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
utf8JsonReadOnlySequence<byte>The UTF-8 JSON document, possibly spanning multiple buffer segments.
pathJsonPathThe pre-parsed path that selects the value.
targetShapeITypeShape<TValue>The shape of
TValue.missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The deserialized value, or the default value when the path is missing and default behavior is selected.
Type Parameters
TValueThe 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
streamStreamThe document stream, which is read to its end and remains open.
pathJsonPathThe raw JSON path.
missingBehaviorMissingPathBehaviorThe behavior for a missing path.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The selected value.
Type Parameters
TValueThe 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
streamStreamThe document stream, which is read to its end and remains open.
pathJsonPathThe raw JSON path.
targetShapeITypeShape<TValue>The selected value shape.
missingBehaviorMissingPathBehaviorThe behavior for a missing path.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The selected value.
Type Parameters
TValueThe 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
utf8JsonReadOnlyMemory<byte>The UTF-8 JSON document.
pathJsonPathThe pre-parsed path that selects the value.
missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The deserialized value, or the default value when the path is missing and default behavior is selected.
Type Parameters
TValueThe 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
utf8JsonReadOnlyMemory<byte>The UTF-8 JSON document.
pathJsonPathThe pre-parsed path that selects the value.
targetShapeITypeShape<TValue>The shape of
TValue.missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The deserialized value, or the default value when the path is missing and default behavior is selected.
Type Parameters
TValueThe 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
jsonstringThe JSON document.
pathJsonPathThe pre-parsed path that selects the value.
missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The deserialized value.
Type Parameters
TValueThe 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
jsonstringThe JSON document.
pathJsonPathThe pre-parsed path that selects the value.
targetShapeITypeShape<TValue>The shape of
TValue.missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The deserialized value, or the default value if the path is missing and
missingBehavioris ReturnDefault.
Type Parameters
TValueThe 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
readerJsonReaderThe reader positioned at the document.
pathJsonPathThe raw path to select.
missingBehaviorMissingPathBehaviorThe behavior for a missing path.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The selected value.
Type Parameters
TValueThe 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
readerJsonReaderThe reader positioned at the root document.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type, which supplies its shape.
TElementThe 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
readerJsonReaderThe reader positioned at the root document.
shapeITypeShape<TRoot>The root type shape.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type.
TElementThe 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
utf8JsonReadOnlySequence<byte>The UTF-8 JSON document, possibly spanning multiple buffer segments.
pathJsonPathThe pre-parsed path that selects the value.
missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The deserialized value, or the default value when the path is missing and default behavior is selected.
Type Parameters
TValueThe 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
utf8JsonReadOnlySequence<byte>The possibly segmented UTF-8 document.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type, which supplies its shape.
TElementThe 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
utf8JsonReadOnlySequence<byte>The possibly segmented UTF-8 document.
shapeITypeShape<TRoot>The root type shape.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type.
TElementThe 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
streamStreamThe document stream, which is read to its end and remains open.
pathJsonPathThe raw JSON path.
missingBehaviorMissingPathBehaviorThe behavior for a missing path.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The selected value.
Type Parameters
TValueThe 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
streamStreamThe document stream, which is read to its end and remains open.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type, which supplies its shape.
TElementThe 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
streamStreamThe document stream, which remains open. The stream is read to its end.
shapeITypeShape<TRoot>The root type shape.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type.
TElementThe 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
utf8JsonReadOnlyMemory<byte>The UTF-8 JSON document.
pathJsonPathThe pre-parsed path that selects the value.
missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The deserialized value, or the default value when the path is missing and default behavior is selected.
Type Parameters
TValueThe 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
utf8JsonReadOnlyMemory<byte>The UTF-8 document.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type, which supplies its shape.
TElementThe 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
utf8JsonReadOnlyMemory<byte>The UTF-8 document.
shapeITypeShape<TRoot>The root type shape.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type.
TElementThe 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
jsonstringThe JSON document.
pathJsonPathThe pre-parsed path that selects the value.
missingBehaviorMissingPathBehaviorControls behavior when the path is not found.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TValue
The deserialized value.
Type Parameters
TValueThe type of the selected value.
TProviderA 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
jsonstringThe JSON document.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type, which supplies its shape.
TElementThe 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
jsonstringThe JSON document.
shapeITypeShape<TRoot>The root type shape.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type.
TElementThe 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
readerJsonReaderThe reader positioned at the root document.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type.
TElementThe selected value type.
TProviderThe 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
utf8JsonReadOnlySequence<byte>The possibly segmented UTF-8 document.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type.
TElementThe selected value type.
TProviderThe 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
streamStreamThe document stream, which is read to its end and remains open.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type.
TElementThe selected value type.
TProviderThe 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
utf8JsonReadOnlyMemory<byte>The UTF-8 document.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type.
TElementThe selected value type.
TProviderThe 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
jsonstringThe JSON document.
optionsJsonSerializer.DeserializePathOptions<TRoot, TElement>The selection options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- TElement
The selected value.
Type Parameters
TRootThe root document type.
TElementThe selected value type.
TProviderThe 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
readerJsonReaderThe reader to deserialize the value from.
shapeITypeShape<T>The type shape describing the structure of
T.startingContextSerializationContextThe 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
TThe type of value to deserialize.
Remarks
Use this overload to supply per-call state to converters via this[object].
Exceptions
- ArgumentException
Thrown if
startingContextbelongs 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
readerJsonReaderThe reader to deserialize the value from.
shapeITypeShape<T>The type shape describing the structure of
T.cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- T
The deserialized value, or null if the JSON represents a null value.
Type Parameters
TThe 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
readerJsonReaderThe reader to deserialize the value from.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- T
The deserialized value, or null if the JSON represents a null value.
Type Parameters
TThe 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
bufferReadOnlySequence<byte>The UTF-8 JSON to deserialize from. Only the first value is deserialized.
shapeITypeShape<T>The type shape describing the structure of
T.cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- T
The deserialized value, or null if the JSON represents a null value.
Type Parameters
TThe 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
bytesReadOnlySequence<byte>cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- T
The deserialized value, or null if the JSON represents a null value.
Type Parameters
TThe 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
streamStreamThe JSON stream.
shapeITypeShape<T>The type shape describing
T.cancellationTokenCancellationTokenA cancellation token.
Returns
- T
The deserialized value.
Type Parameters
TThe 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
streamStreamThe JSON stream.
cancellationTokenCancellationTokenA cancellation token.
Returns
- T
The deserialized value.
Type Parameters
TThe 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
bufferReadOnlyMemory<byte>The UTF-8 JSON to deserialize from. Only the first value is deserialized.
shapeITypeShape<T>The type shape describing the structure of
T.cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- T
The deserialized value, or null if the JSON represents a null value.
Type Parameters
TThe 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
bytesReadOnlyMemory<byte>cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- T
The deserialized value, or null if the JSON represents a null value.
Type Parameters
TThe 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
jsonstringThe JSON text.
shapeITypeShape<T>The type shape describing
T.cancellationTokenCancellationTokenA cancellation token.
Returns
- T
The deserialized value.
Type Parameters
TThe 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
jsonstringThe JSON text.
cancellationTokenCancellationTokenA cancellation token.
Returns
- T
The deserialized value.
Type Parameters
TThe 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
readerJsonReaderThe reader to deserialize the value from.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- T
The deserialized value, or null if the JSON represents a null value.
Type Parameters
TThe 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
bytesReadOnlySequence<byte>cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- T
The deserialized value, or null if the JSON represents a null value.
Type Parameters
TThe 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
streamStreamThe JSON stream.
cancellationTokenCancellationTokenA cancellation token.
Returns
- T
The deserialized value.
Type Parameters
TThe 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
bytesReadOnlyMemory<byte>cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- T
The deserialized value, or null if the JSON represents a null value.
Type Parameters
TThe 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
jsonstringThe JSON text.
cancellationTokenCancellationTokenA cancellation token.
Returns
- T
The deserialized value.
Type Parameters
TThe 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
typeShapeITypeShapeThe 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
typeShapeITypeShapeThe shape of the type.
optionsJsonSchemaOptionsThe 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
TThe 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
optionsJsonSchemaOptionsThe schema generation options.
Returns
- JsonObject
The JSON Schema document as a JSON object.
Type Parameters
TThe 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
providerITypeShapeProviderThe type shape provider.
Returns
- JsonObject
The JSON Schema document.
Type Parameters
TThe 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
providerITypeShapeProviderThe type shape provider.
optionsJsonSchemaOptionsThe schema generation options.
Returns
- JsonObject
The JSON Schema document.
Type Parameters
TThe 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
shapeITypeShape<T>The shape of the type.
Returns
- JsonObject
The JSON Schema document as a JSON object.
Type Parameters
TThe 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
shapeITypeShape<T>The shape of the type.
optionsJsonSchemaOptionsThe schema generation options.
Returns
- JsonObject
The JSON Schema document as a JSON object.
Type Parameters
TThe 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
TThe type to describe.
TProviderA 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
optionsJsonSchemaOptionsThe schema generation options.
Returns
- JsonObject
The JSON Schema document as a JSON object.
Type Parameters
TThe type to describe.
TProviderA 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
writerPipeWriterThe pipe to write to. It is flushed but never completed by this method.
valuesIAsyncEnumerable<T>The asynchronous source of elements.
shapeITypeShape<T>The shape of
T.cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the serialization.
Type Parameters
TThe 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
writerPipeWriterThe pipe to write to. It is flushed but never completed by this method.
valuesIAsyncEnumerable<T>The asynchronous source of elements.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the serialization.
Type Parameters
TThe 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
streamStreamThe stream to write to. It is flushed but not disposed or closed by this method.
valuesIAsyncEnumerable<T>The asynchronous source of elements.
shapeITypeShape<T>The shape of
T.cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the serialization.
Type Parameters
TThe 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
streamStreamThe stream to write to. It is flushed but not disposed or closed by this method.
valuesIAsyncEnumerable<T>The asynchronous source of elements.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the serialization.
Type Parameters
TThe 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
writerPipeWriterThe pipe to write to. It is flushed but never completed by this method.
valueTThe value to serialize.
startingContextSerializationContextThe 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
TThe type of value to serialize.
Remarks
Use this overload to supply per-call state to converters via this[object].
Exceptions
- ArgumentException
Thrown if
startingContextbelongs 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
writerPipeWriterThe pipe to write to. It is flushed but never completed by this method.
valueTThe value to serialize.
shapeITypeShape<T>The type shape describing
T.startingContextSerializationContextThe 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
TThe type of value to serialize.
Remarks
Use this overload to supply per-call state to converters via this[object].
Exceptions
- ArgumentException
Thrown if
startingContextbelongs 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
writerPipeWriterThe pipe to write to. It is flushed but never completed by this method.
valueTThe value to serialize.
shapeITypeShape<T>The type shape describing
T.cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the asynchronous serialization.
Type Parameters
TThe 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
writerPipeWriterThe pipe to write to. It is flushed but never completed by this method.
valueTThe value to serialize.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the asynchronous serialization.
Type Parameters
TThe 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
streamStreamThe destination stream, which is left open.
valueTThe value to serialize.
startingContextSerializationContextThe inactive starting context.
Returns
- ValueTask
A task tracking the write.
Type Parameters
TThe 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
streamStreamThe destination stream, which is left open.
valueTThe value to serialize.
shapeITypeShape<T>The shape describing the value.
startingContextSerializationContextThe inactive starting context.
Returns
- ValueTask
A task tracking the write.
Type Parameters
TThe 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
streamStreamThe destination stream. It is flushed but not disposed or closed by this method.
valueTThe value to serialize.
shapeITypeShape<T>The type shape describing
T.cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the asynchronous serialization.
Type Parameters
TThe 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
streamStreamThe destination stream. It is flushed but not disposed or closed by this method.
valueTThe value to serialize.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the asynchronous serialization.
Type Parameters
TThe 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
writerPipeWriterThe pipe to write to. It is flushed but never completed by this method.
valueTThe value to serialize.
startingContextSerializationContextThe 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
TThe type of value to serialize.
TProvider
Remarks
Use this overload to supply per-call state to converters via this[object].
Exceptions
- ArgumentException
Thrown if
startingContextbelongs 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
writerPipeWriterThe pipe to write to. It is flushed but never completed by this method.
valueTThe value to serialize.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the asynchronous serialization.
Type Parameters
TThe 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
streamStreamThe destination stream, which is left open.
valueTThe value to serialize.
startingContextSerializationContextThe inactive starting context.
Returns
- ValueTask
A task tracking the write.
Type Parameters
TThe 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
streamStreamThe destination stream. It is flushed but not disposed or closed by this method.
valueTThe value to serialize.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the asynchronous serialization.
Type Parameters
TThe 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
writerPipeWriterThe pipe to write to. It is flushed but never completed by this method.
valuesIAsyncEnumerable<T>The asynchronous source of values.
optionsJsonSerializer.SequenceOptionsThe framing options. The default is newline-delimited JSON.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the serialization.
Type Parameters
TThe 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
writerPipeWriterThe pipe to write to. It is flushed but never completed by this method.
valuesIAsyncEnumerable<T>The asynchronous source of values.
shapeITypeShape<T>The shape of
T.optionsJsonSerializer.SequenceOptionsThe framing options. The default is newline-delimited JSON.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the serialization.
Type Parameters
TThe 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
streamStreamThe stream to write to. It is flushed but not disposed or closed by this method.
valuesIAsyncEnumerable<T>The asynchronous source of values.
optionsJsonSerializer.SequenceOptionsThe framing options. The default is newline-delimited JSON.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the serialization.
Type Parameters
TThe 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
streamStreamThe stream to write to. It is flushed but not disposed or closed by this method.
valuesIAsyncEnumerable<T>The asynchronous source of values.
shapeITypeShape<T>The shape of
T.optionsJsonSerializer.SequenceOptionsThe framing options. The default is newline-delimited JSON.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the serialization.
Type Parameters
TThe 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
writerPipeWriterThe pipe to write to. It is flushed but never completed by this method.
valuesIAsyncEnumerable<T>The asynchronous source of values.
optionsJsonSerializer.SequenceOptionsThe framing options. The default is newline-delimited JSON.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the serialization.
Type Parameters
TThe 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
streamStreamThe stream to write to. It is flushed but not disposed or closed by this method.
valuesIAsyncEnumerable<T>The asynchronous source of values.
optionsJsonSerializer.SequenceOptionsThe framing options. The default is newline-delimited JSON.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the serialization.
Type Parameters
TThe value type.
TProvider
SerializeJsonValue(JsonValue?, CancellationToken)
Serializes a JsonValue to JSON text.
public string SerializeJsonValue(JsonValue? value, CancellationToken cancellationToken = default)
Parameters
valueJsonValueThe value to serialize.
cancellationTokenCancellationTokenA 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
writerIBufferWriter<byte>The destination buffer.
valueJsonValueThe value to serialize.
cancellationTokenCancellationTokenA 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
streamStreamThe destination stream. It is flushed but not disposed by this method.
valueJsonValueThe value to serialize.
cancellationTokenCancellationTokenA 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
writerPipeWriterThe pipe. It is flushed but not completed by this method.
valueJsonValueThe value to serialize.
cancellationTokenCancellationTokenA cancellation token.
Returns
- ValueTask
A task tracking the serialization.
SerializeJsonValueAsync(Stream, JsonValue?, CancellationToken)
public ValueTask SerializeJsonValueAsync(Stream stream, JsonValue? value, CancellationToken cancellationToken = default)
Parameters
streamStreamThe destination stream. It is flushed but not disposed by this method.
valueJsonValueThe value to serialize.
cancellationTokenCancellationTokenA 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
writerJsonWriterThe writer to serialize the value into.
valueobjectThe value to serialize.
shapeITypeShapeThe type shape describing the structure of
value.startingContextSerializationContextThe context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.
Exceptions
- ArgumentException
Thrown if
startingContextbelongs 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
writerJsonWriterThe writer to serialize the value into.
valueobjectThe value to serialize.
shapeITypeShapeThe type shape describing the structure of
value.cancellationTokenCancellationTokenA 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
writerIBufferWriter<byte>The writer to serialize the value into.
valueobjectThe value to serialize.
shapeITypeShapeThe type shape describing the structure of
value.cancellationTokenCancellationTokenA 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
streamStreamThe destination stream.
valueobjectThe value to serialize.
shapeITypeShapeThe type shape describing the structure of
value.cancellationTokenCancellationTokenA 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
valueobjectThe value to serialize.
shapeITypeShapeThe type shape describing the structure of
value.cancellationTokenCancellationTokenA 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
writerPipeWriterThe destination pipe, which is not completed.
valueobjectThe value to serialize.
shapeITypeShapeThe shape describing the value.
startingContextSerializationContextThe 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
writerPipeWriterThe destination pipe, which is not completed.
valueobjectThe value to serialize.
shapeITypeShapeThe shape describing the value.
cancellationTokenCancellationTokenA 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
streamStreamThe destination stream, which is left open.
valueobjectThe value to serialize.
shapeITypeShapeThe shape describing the value.
startingContextSerializationContextThe 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
streamStreamThe destination stream, which is left open.
valueobjectThe value to serialize.
shapeITypeShapeThe shape describing the value.
cancellationTokenCancellationTokenA 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
writerJsonWriterThe writer to serialize the value into.
valueTThe value to serialize.
shapeITypeShape<T>The type shape describing the structure of
T.startingContextSerializationContextThe context to start this operation with, used instead of StartingContext. Its CancellationToken cancels the operation.
Type Parameters
TThe type of value to serialize.
Remarks
Use this overload to supply per-call state to converters via this[object].
Exceptions
- ArgumentException
Thrown if
startingContextbelongs 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
writerJsonWriterThe writer to serialize the value into.
valueTThe value to serialize.
shapeITypeShape<T>The type shape describing the structure of
T.cancellationTokenCancellationTokenA token to cancel the operation.
Type Parameters
TThe 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
writerJsonWriterThe writer to serialize the value into.
valueTThe value to serialize.
cancellationTokenCancellationTokenA token to cancel the operation.
Type Parameters
TThe 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
writerIBufferWriter<byte>The destination buffer.
valueTThe value to serialize.
shapeITypeShape<T>The type shape describing
T.cancellationTokenCancellationTokenA cancellation token.
Type Parameters
TThe 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
writerIBufferWriter<byte>The destination buffer.
valueTThe value to serialize.
cancellationTokenCancellationTokenA cancellation token.
Type Parameters
TThe 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
streamStreamThe destination stream.
valueTThe value to serialize.
shapeITypeShape<T>The type shape describing
T.cancellationTokenCancellationTokenA cancellation token.
Type Parameters
TThe 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
streamStreamThe destination stream.
valueTThe value to serialize.
cancellationTokenCancellationTokenA cancellation token.
Type Parameters
TThe 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
valueTThe value to serialize.
shapeITypeShape<T>The type shape describing
T.cancellationTokenCancellationTokenA cancellation token.
Returns
- string
The serialized JSON text.
Type Parameters
TThe 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
valueTThe value to serialize.
cancellationTokenCancellationTokenA cancellation token.
Returns
- string
The serialized JSON text.
Type Parameters
TThe 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
writerJsonWriterThe writer to serialize the value into.
valueTThe value to serialize.
cancellationTokenCancellationTokenA token to cancel the operation.
Type Parameters
TThe 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
writerIBufferWriter<byte>The destination buffer.
valueTThe value to serialize.
cancellationTokenCancellationTokenA cancellation token.
Type Parameters
TThe 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
streamStreamThe destination stream.
valueTThe value to serialize.
cancellationTokenCancellationTokenA cancellation token.
Type Parameters
TThe 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
valueTThe value to serialize.
cancellationTokenCancellationTokenA cancellation token.
Returns
- string
The serialized JSON text.
Type Parameters
TThe type of value to serialize.
TProvider