Class JsonSerializerExtensions
- Namespace
- Nerdbank.Json
- Assembly
- Nerdbank.Json.dll
Extension methods for the JsonSerializer class.
public static class JsonSerializerExtensions
- Inheritance
-
JsonSerializerExtensions
- Inherited Members
Remarks
These extension methods preserve the convenient serializer entry points for target frameworks
that cannot use the constrained IShapeable<T> instance overloads, and for values that
rely on dynamic shape discovery or witness types.
Some of these methods will be very typical when targeting .NET Standard or .NET Framework, but when targeting .NET, the compiler will prefer the instance methods on the JsonSerializer class itself. These instance methods are faster and produce compile errors rather than runtime exceptions that may be thrown by these extension methods.
Methods
DeserializeEnumerableAsync<T>(JsonSerializer, PipeReader, SequenceOptions, CancellationToken)
Asynchronously streams JSON values using the selected framing.
public static IAsyncEnumerable<T?> DeserializeEnumerableAsync<T>(this JsonSerializer self, PipeReader reader, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerreaderPipeReaderThe 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>(JsonSerializer, Stream, SequenceOptions, CancellationToken)
Asynchronously streams JSON values from a stream using the selected framing.
public static IAsyncEnumerable<T?> DeserializeEnumerableAsync<T>(this JsonSerializer self, Stream stream, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerstreamStreamThe 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, TProvider>(JsonSerializer, PipeReader, SequenceOptions, CancellationToken)
Asynchronously streams JSON values using the selected framing.
public static IAsyncEnumerable<T?> DeserializeEnumerableAsync<T, TProvider>(this JsonSerializer self, PipeReader reader, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerreaderPipeReaderThe 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>(JsonSerializer, Stream, SequenceOptions, CancellationToken)
Asynchronously streams JSON values from a stream using the selected framing.
public static IAsyncEnumerable<T?> DeserializeEnumerableAsync<T, TProvider>(this JsonSerializer self, Stream stream, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerstreamStreamThe 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
DeserializePathEnumerableAsync<TElement>(JsonSerializer, 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 static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement>(this JsonSerializer self, PipeReader reader, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerreaderPipeReaderThe 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>(JsonSerializer, Stream, JsonPath, MissingPathBehavior, CancellationToken)
Asynchronously streams the elements of a JSON array selected by a pre-parsed JsonPath from a stream.
public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement>(this JsonSerializer self, Stream stream, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerstreamStreamThe 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, TProvider>(JsonSerializer, 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 static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement, TProvider>(this JsonSerializer self, PipeReader reader, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerreaderPipeReaderThe 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>(JsonSerializer, PipeReader, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)
Streams the array selected by a typed path, without buffering the enclosing document.
public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement>(this JsonSerializer self, PipeReader reader, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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.
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>(JsonSerializer, Stream, JsonPath, MissingPathBehavior, CancellationToken)
Asynchronously streams the elements of a JSON array selected by a pre-parsed JsonPath from a stream.
public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TElement, TProvider>(this JsonSerializer self, Stream stream, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerstreamStreamThe 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>(JsonSerializer, Stream, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)
Streams the array selected by a typed path, without buffering the enclosing document.
public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement>(this JsonSerializer self, Stream stream, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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.
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>(JsonSerializer, PipeReader, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)
Streams the array selected by a typed path, without buffering the enclosing document.
public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement, TProvider>(this JsonSerializer self, PipeReader reader, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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>(JsonSerializer, Stream, StreamingEnumerationOptions<TRoot, TElement>, CancellationToken)
Streams the array selected by a typed path, without buffering the enclosing document.
public static IAsyncEnumerable<TElement?> DeserializePathEnumerableAsync<TRoot, TElement, TProvider>(this JsonSerializer self, Stream stream, JsonSerializer.StreamingEnumerationOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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>(JsonSerializer, ref JsonReader, JsonPath, MissingPathBehavior, CancellationToken)
Deserializes a raw JSON path from a reader.
public static TValue? DeserializePath<TValue>(this JsonSerializer self, ref JsonReader reader, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerreaderJsonReaderThe 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>(JsonSerializer, 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 static TValue? DeserializePath<TValue>(this JsonSerializer self, scoped in ReadOnlySequence<byte> utf8Json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerutf8JsonReadOnlySequence<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>(JsonSerializer, Stream, JsonPath, MissingPathBehavior, CancellationToken)
Deserializes a raw JSON path from a stream.
public static TValue? DeserializePath<TValue>(this JsonSerializer self, Stream stream, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerstreamStreamThe 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>(JsonSerializer, ReadOnlyMemory<byte>, JsonPath, MissingPathBehavior, CancellationToken)
Deserializes only the value selected by a pre-parsed JsonPath from a UTF-8 buffer.
public static TValue? DeserializePath<TValue>(this JsonSerializer self, ReadOnlyMemory<byte> utf8Json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerutf8JsonReadOnlyMemory<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>(JsonSerializer, string, JsonPath, MissingPathBehavior, CancellationToken)
Deserializes only the value selected by a pre-parsed JsonPath, skipping unrelated JSON.
public static TValue? DeserializePath<TValue>(this JsonSerializer self, string json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerjsonstringThe 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 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>(JsonSerializer, ref JsonReader, JsonPath, MissingPathBehavior, CancellationToken)
Deserializes a raw JSON path from a reader.
public static TValue? DeserializePath<TValue, TProvider>(this JsonSerializer self, ref JsonReader reader, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerreaderJsonReaderThe 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>(JsonSerializer, ref JsonReader, in DeserializePathOptions<TRoot, TElement>, CancellationToken)
Deserializes a value selected by an expression, leaving the reader immediately after that value.
public static TElement? DeserializePath<TRoot, TElement>(this JsonSerializer self, ref JsonReader reader, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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.
DeserializePath<TValue, TProvider>(JsonSerializer, 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 static TValue? DeserializePath<TValue, TProvider>(this JsonSerializer self, scoped in ReadOnlySequence<byte> utf8Json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerutf8JsonReadOnlySequence<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>(JsonSerializer, scoped in ReadOnlySequence<byte>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)
Deserializes a value selected by an expression, leaving the reader immediately after that value.
public static TElement? DeserializePath<TRoot, TElement>(this JsonSerializer self, scoped in ReadOnlySequence<byte> utf8Json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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.
DeserializePath<TValue, TProvider>(JsonSerializer, Stream, JsonPath, MissingPathBehavior, CancellationToken)
Deserializes a raw JSON path from a stream.
public static TValue? DeserializePath<TValue, TProvider>(this JsonSerializer self, Stream stream, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerstreamStreamThe 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>(JsonSerializer, Stream, in DeserializePathOptions<TRoot, TElement>, CancellationToken)
Deserializes a value selected by an expression, leaving the reader immediately after that value.
public static TElement? DeserializePath<TRoot, TElement>(this JsonSerializer self, Stream stream, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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.
DeserializePath<TValue, TProvider>(JsonSerializer, ReadOnlyMemory<byte>, JsonPath, MissingPathBehavior, CancellationToken)
Deserializes only the value selected by a pre-parsed JsonPath from a UTF-8 buffer.
public static TValue? DeserializePath<TValue, TProvider>(this JsonSerializer self, ReadOnlyMemory<byte> utf8Json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerutf8JsonReadOnlyMemory<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>(JsonSerializer, ReadOnlyMemory<byte>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)
Deserializes a value selected by an expression, leaving the reader immediately after that value.
public static TElement? DeserializePath<TRoot, TElement>(this JsonSerializer self, ReadOnlyMemory<byte> utf8Json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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.
DeserializePath<TValue, TProvider>(JsonSerializer, string, JsonPath, MissingPathBehavior, CancellationToken)
Deserializes only the value selected by a pre-parsed JsonPath, skipping unrelated JSON.
public static TValue? DeserializePath<TValue, TProvider>(this JsonSerializer self, string json, JsonPath path, MissingPathBehavior missingBehavior = MissingPathBehavior.Throw, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerjsonstringThe 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 if the path is missing and
missingBehavioris ReturnDefault.
Type Parameters
TValueThe type of the selected value.
TProvider
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<TRoot, TElement>(JsonSerializer, string, in DeserializePathOptions<TRoot, TElement>, CancellationToken)
Deserializes a value selected by an expression, leaving the reader immediately after that value.
public static TElement? DeserializePath<TRoot, TElement>(this JsonSerializer self, string json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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.
DeserializePath<TRoot, TElement, TProvider>(JsonSerializer, ref JsonReader, in DeserializePathOptions<TRoot, TElement>, CancellationToken)
Deserializes a value selected by an expression, leaving the reader immediately after that value.
public static TElement? DeserializePath<TRoot, TElement, TProvider>(this JsonSerializer self, ref JsonReader reader, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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>(JsonSerializer, scoped in ReadOnlySequence<byte>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)
Deserializes a value selected by an expression, leaving the reader immediately after that value.
public static TElement? DeserializePath<TRoot, TElement, TProvider>(this JsonSerializer self, scoped in ReadOnlySequence<byte> utf8Json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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>(JsonSerializer, Stream, in DeserializePathOptions<TRoot, TElement>, CancellationToken)
Deserializes a value selected by an expression, leaving the reader immediately after that value.
public static TElement? DeserializePath<TRoot, TElement, TProvider>(this JsonSerializer self, Stream stream, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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>(JsonSerializer, ReadOnlyMemory<byte>, in DeserializePathOptions<TRoot, TElement>, CancellationToken)
Deserializes a value selected by an expression, leaving the reader immediately after that value.
public static TElement? DeserializePath<TRoot, TElement, TProvider>(this JsonSerializer self, ReadOnlyMemory<byte> utf8Json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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>(JsonSerializer, string, in DeserializePathOptions<TRoot, TElement>, CancellationToken)
Deserializes a value selected by an expression, leaving the reader immediately after that value.
public static TElement? DeserializePath<TRoot, TElement, TProvider>(this JsonSerializer self, string json, in JsonSerializer.DeserializePathOptions<TRoot, TElement> options, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerThe serializer.
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.
SerializeEnumerableAsync<T>(JsonSerializer, PipeWriter, IAsyncEnumerable<T>, SequenceOptions, CancellationToken)
Asynchronously serializes an IAsyncEnumerable<T> using the selected JSON framing.
public static ValueTask SerializeEnumerableAsync<T>(this JsonSerializer self, PipeWriter writer, IAsyncEnumerable<T> values, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerwriterPipeWriterThe 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>(JsonSerializer, Stream, IAsyncEnumerable<T>, SequenceOptions, CancellationToken)
Asynchronously serializes an IAsyncEnumerable<T> to a stream using the selected JSON framing.
public static ValueTask SerializeEnumerableAsync<T>(this JsonSerializer self, Stream stream, IAsyncEnumerable<T> values, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerstreamStreamThe 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, TProvider>(JsonSerializer, PipeWriter, IAsyncEnumerable<T>, SequenceOptions, CancellationToken)
Asynchronously serializes an IAsyncEnumerable<T> using the selected JSON framing.
public static ValueTask SerializeEnumerableAsync<T, TProvider>(this JsonSerializer self, PipeWriter writer, IAsyncEnumerable<T> values, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerwriterPipeWriterThe 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>(JsonSerializer, Stream, IAsyncEnumerable<T>, SequenceOptions, CancellationToken)
Asynchronously serializes an IAsyncEnumerable<T> to a stream using the selected JSON framing.
public static ValueTask SerializeEnumerableAsync<T, TProvider>(this JsonSerializer self, Stream stream, IAsyncEnumerable<T> values, JsonSerializer.SequenceOptions options = default, CancellationToken cancellationToken = default)
Parameters
selfJsonSerializerstreamStreamThe 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