Class DefaultJsonStreamReader
Newtonsoft.Json based implementation of IJsonStreamReader.
Inherited Members
Namespace: Couchbase.Core.IO.Serializers
Assembly: Couchbase.NetClient.dll
Syntax
public class DefaultJsonStreamReader : IJsonStreamReader, IDisposable
Constructors
| Edit this page View SourceDefaultJsonStreamReader(Stream, JsonSerializer)
Creates a new DefaultJsonStreamReader.
Declaration
public DefaultJsonStreamReader(Stream stream, JsonSerializer deserializer)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream to read. |
JsonSerializer | deserializer | The Newtonsoft.Json.JsonSerializer to use for deserializing objects. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Properties
| Edit this page View SourceDepth
The current depth of the reader. Zero indicates ready to read the root object, one indicates an attribute on the root object, etc.
Declaration
public int Depth { get; }
Property Value
Type | Description |
---|---|
int |
Remarks
Example paths: "metrics" == 1, "metrics.count" == 2, "results[0].abv" == 3.
Deserializer
The Newtonsoft.Json.JsonSerializer to use for deserializing objects.
Declaration
public JsonSerializer Deserializer { get; }
Property Value
Type | Description |
---|---|
JsonSerializer |
Value
If the reader is stopped on a simple value attribute, returns the value.
Declaration
public object? Value { get; }
Property Value
Type | Description |
---|---|
object |
ValueType
If the reader is stopped on a simple value attribute, returns the .NET type of the value. Otherwise, returns null.
Declaration
public Type? ValueType { get; }
Property Value
Type | Description |
---|---|
Type |
Methods
| Edit this page View SourceDispose()
Declaration
public void Dispose()
InitializeAsync(CancellationToken)
Initializes the reader
Declaration
public Task<bool> InitializeAsync(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Cancellation token. |
Returns
Type | Description |
---|---|
Task<bool> |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | InitializeAsync should only be called once. |
ReadArrayAsync<T>(Func<IJsonStreamReader, CancellationToken, Task<T>>, CancellationToken)
Reads an array of tokens at the current point in the stream.
Declaration
public IAsyncEnumerable<T> ReadArrayAsync<T>(Func<IJsonStreamReader, CancellationToken, Task<T>> readElement, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Func<IJsonStreamReader, CancellationToken, Task<T>> | readElement | Function which reads each element of the array. |
CancellationToken | cancellationToken | Cancellation token. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<T> | An IAsyncEnumerable<T> to read the array. |
Type Parameters
Name | Description |
---|---|
T | Type of elements returned. |
ReadObjectAsync<T>(CancellationToken)
Reads an object at the current point in the stream.
Declaration
public Task<T> ReadObjectAsync<T>(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Cancellation token. |
Returns
Type | Description |
---|---|
Task<T> | The object read. |
Type Parameters
Name | Description |
---|---|
T | Type of the object to read. |
Remarks
This method also supports reading literals such as strings, numbers, nulls, etc,
given the correct type for T
.
ReadToNextAttributeAsync(CancellationToken)
Reads until the next attribute is found in the stream. Returns the path to the attribute,
or
Declaration
public Task<string?> ReadToNextAttributeAsync(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Cancellation token. |
Returns
Type | Description |
---|---|
Task<string> | Path to the attribute relative to the overall stream,
or |
Remarks
The returned path is "." separated, and relative to the overall stream. For example, if the attribute "metrics" is on the root object, returns "metrics". If the attribute reached is "count" on the "metrics" object, the returned value is "metrics.count". Arrays are indicated with square brackets, for example "results[0].abv".
ReadTokenAsync(CancellationToken)
Reads a dynamic token at the current point in the stream.
Declaration
public Task<IJsonToken> ReadTokenAsync(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Cancellation token. |
Returns
Type | Description |
---|---|
Task<IJsonToken> | The dynamic object. |