Couchbase .NET SDK | 3.7.2
Search Results for

    Show / Hide Table of Contents

    Class DefaultJsonStreamReader

    Newtonsoft.Json based implementation of IJsonStreamReader.

    Inheritance
    object
    DefaultJsonStreamReader
    Implements
    IJsonStreamReader
    IDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Couchbase.Core.IO.Serializers
    Assembly: Couchbase.NetClient.dll
    Syntax
    public class DefaultJsonStreamReader : IJsonStreamReader, IDisposable

    Constructors

    | Edit this page View Source

    DefaultJsonStreamReader(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

    stream or deserializer is null.

    Properties

    | Edit this page View Source

    Depth

    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.

    | Edit this page View Source

    Deserializer

    The Newtonsoft.Json.JsonSerializer to use for deserializing objects.

    Declaration
    public JsonSerializer Deserializer { get; }
    Property Value
    Type Description
    JsonSerializer
    | Edit this page View Source

    Value

    If the reader is stopped on a simple value attribute, returns the value.

    Declaration
    public object? Value { get; }
    Property Value
    Type Description
    object
    | Edit this page View Source

    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 Source

    Dispose()

    Declaration
    public void Dispose()
    | Edit this page View Source

    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>

    true if successfully initialized.

    Exceptions
    Type Condition
    InvalidOperationException

    InitializeAsync should only be called once.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    ReadToNextAttributeAsync(CancellationToken)

    Reads until the next attribute is found in the stream. Returns the path to the attribute, or null if the end of the stream is reached.

    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 null if the end of the stream is reached"

    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".

    | Edit this page View Source

    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.

    Implements

    IJsonStreamReader
    IDisposable

    Extension Methods

    JsonStreamDeserializerExtensions.ReadObjectsAsync<T>(IJsonStreamReader, CancellationToken)
    JsonStreamDeserializerExtensions.ReadTokensAsync(IJsonStreamReader, CancellationToken)
    • Edit this page
    • View Source
    In this article
    Back to top © 2025 Couchbase, Inc.