Couchbase .NET SDK __CB_SDK_VERSION__

Show / Hide Table of Contents

Class SystemTextJsonSerializer

A JSON serializer based on System.Text.Json.

Inheritance
object
SystemTextJsonSerializer
Implements
IExtendedTypeSerializer
IProjectableTypeDeserializer
IStreamingTypeDeserializer
IBufferedTypeSerializer
ITypeSerializer
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: Couchbase.Core.IO.Serializers
Assembly: Couchbase.NetClient.dll
Syntax
[InterfaceStability(Level.Volatile)]
public abstract class SystemTextJsonSerializer : IExtendedTypeSerializer, IProjectableTypeDeserializer, IStreamingTypeDeserializer, IBufferedTypeSerializer, ITypeSerializer
Remarks

This class is currently experimental and subject to change. It does not support all serialization features supported by the DefaultSerializer. Known limitations currently include:

  • Couchbase.Transactions is not currently supported.
  • No support for dynamic types.
  • Some properties of QueryMetaData which use dynamic, such as Profile and Signature, are not populated.
  • View-style queries are not supported using JsonSerializerContext, only reflection-based serialization.
  • Any use of Newtonsoft.Json.Linq.JToken should be replaced with JsonElement or object.

Constructors

View Source

SystemTextJsonSerializer()

Declaration
protected SystemTextJsonSerializer()

Properties

View Source

DeserializationOptions

Provides custom deserialization options. Options not listed in SupportedDeserializationOptions will be ignored. If null, then defaults will be used.

Declaration
public DeserializationOptions? DeserializationOptions { get; set; }
Property Value
Type Description
DeserializationOptions
View Source

Options

JsonSerializerOptions used for serialization and deserialization.

Declaration
public abstract JsonSerializerOptions Options { get; }
Property Value
Type Description
JsonSerializerOptions
View Source

SupportedDeserializationOptions

Informs consumers what deserialization options this IExtendedTypeSerializer supports.

Declaration
public SupportedDeserializationOptions SupportedDeserializationOptions { get; }
Property Value
Type Description
SupportedDeserializationOptions

Methods

View Source

CanSerialize(Type)

Determines if the serializer can serialize and deserialize the specified type.

Declaration
public abstract bool CanSerialize(Type type)
Parameters
Type Name Description
Type type

Type of object to serialize or deserialize.

Returns
Type Description
bool

true if the type can be serialized and deserialized.

View Source

Create(bool)

Create a new SystemTextJsonSerializer with default options, optionally enabling increased Newtonsoft.Json compatibility.

Declaration
[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonSerializerContext, or make sure all of the required types are preserved.")]
[RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonSerializerContext.")]
public static SystemTextJsonSerializer Create(bool increasedNewtonsoftCompatibility = false)
Parameters
Type Name Description
bool increasedNewtonsoftCompatibility

Enable increased Newtonsoft.Json compatibility.

Returns
Type Description
SystemTextJsonSerializer

A new SystemTextJsonSerializer.

Remarks

The increasedNewtonsoftCompatibility parameter doesn't make this fully compatible with Newtonsoft.Json. However, it does enable several features to make it more compatible such as case-insensitive property name deserialization, ignoring comments and trailing commas, serializing public fields, etc. For details on compatibility, see https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-migrate-from-newtonsoft-how-to

View Source

Create(JsonSerializerOptions)

Create a new SystemTextJsonSerializer with supplied JsonSerializerOptions.

Declaration
[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonSerializerContext, or make sure all of the required types are preserved.")]
[RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonSerializerContext.")]
public static SystemTextJsonSerializer Create(JsonSerializerOptions options)
Parameters
Type Name Description
JsonSerializerOptions options

JsonSerializerOptions to control serialization and deserialization.

Returns
Type Description
SystemTextJsonSerializer

A new SystemTextJsonSerializer.

View Source

Create(JsonSerializerContext)

Create a new SystemTextJsonSerializer using a supplied JsonSerializerContext.

Declaration
public static SystemTextJsonSerializer Create(JsonSerializerContext context)
Parameters
Type Name Description
JsonSerializerContext context

JsonSerializerOptions to use for serialization and deserialization.

Returns
Type Description
SystemTextJsonSerializer

A new SystemTextJsonSerializer.

Remarks

This overload should be used to supply custom serializers on a per-request basis that are optimized for the particular type being serialized or deserialized. Any type which isn't registered in the JsonSerializerContext will be handled using the Options.

View Source

CreateJsonStreamReader(Stream)

Create an IJsonStreamReader for parsing a Stream.

Declaration
public abstract IJsonStreamReader CreateJsonStreamReader(Stream stream)
Parameters
Type Name Description
Stream stream

Stream to parse.

Returns
Type Description
IJsonStreamReader

The new IJsonStreamReader.

View Source

CreateProjectionBuilder(ILogger)

Create a new IProjectionBuilder based on this serializer.

Declaration
public abstract IProjectionBuilder CreateProjectionBuilder(ILogger logger)
Parameters
Type Name Description
ILogger logger

Logger for logging warnings or errors.

Returns
Type Description
IProjectionBuilder

A new IProjectionBuilder.

View Source

DeserializeAsync<T>(Stream, CancellationToken)

Deserializes the specified stream into the Type T specified as a generic parameter.

Declaration
public abstract ValueTask<T?> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default)
Parameters
Type Name Description
Stream stream

The stream.

CancellationToken cancellationToken

Cancellation token.

Returns
Type Description
ValueTask<T>

The Type instance representing the value of the key.

Type Parameters
Name Description
T

The Type specified as the type of the value.

View Source

Deserialize<T>(ReadOnlySequence<byte>)

Deserializes the specified buffer into the type specified by T.

Declaration
public abstract T? Deserialize<T>(ReadOnlySequence<byte> buffer)
Parameters
Type Name Description
ReadOnlySequence<byte> buffer

The buffer to deserialize from.

Returns
Type Description
T

The deserialized value.

Type Parameters
Name Description
T

The type of the value.

View Source

Deserialize<T>(Stream)

Deserializes the specified stream into the Type T specified as a generic parameter.

Declaration
public abstract T? Deserialize<T>(Stream stream)
Parameters
Type Name Description
Stream stream

The stream.

Returns
Type Description
T

The Type instance representing the value of the key.

Type Parameters
Name Description
T

The Type specified as the type of the value.

View Source

Deserialize<T>(ReadOnlyMemory<byte>)

Deserializes the specified buffer into the Type T specified as a generic parameter.

Declaration
public abstract T? Deserialize<T>(ReadOnlyMemory<byte> buffer)
Parameters
Type Name Description
ReadOnlyMemory<byte> buffer

The buffer to deserialize from.

Returns
Type Description
T

The Type instance representing the value of the key.

Type Parameters
Name Description
T

The Type specified as the type of the value.

View Source

GetMemberName(MemberInfo)

Get the name which will be used for a given member during serialization/deserialization.

Declaration
public string? GetMemberName(MemberInfo member)
Parameters
Type Name Description
MemberInfo member

Returns the name of this member.

Returns
Type Description
string

The name which will be used for a given member during serialization/deserialization, or null if if will not be serialized.

View Source

Serialize(Stream, object?)

Serializes the specified object onto a stream.

Declaration
public abstract void Serialize(Stream stream, object? obj)
Parameters
Type Name Description
Stream stream

The stream to receive the serialized object.

object obj

The object to serialize.

Remarks

This overload does not make use of JsonSerializerContext.

View Source

Serialize(Utf8JsonWriter, object?)

Serializes the specified object onto a Utf8JsonWriter.

Declaration
public abstract void Serialize(Utf8JsonWriter stream, object? obj)
Parameters
Type Name Description
Utf8JsonWriter stream

The writer to receive the serialized object.

object obj

The object to serialize.

View Source

SerializeAsync(Stream, object?, CancellationToken)

Serializes the specified object onto a stream.

Declaration
public abstract ValueTask SerializeAsync(Stream stream, object? obj, CancellationToken cancellationToken = default)
Parameters
Type Name Description
Stream stream

The stream to receive the serialized object.

object obj

The object to serialize.

CancellationToken cancellationToken

Cancellation token.

Returns
Type Description
ValueTask
Remarks

This overload does not make use of JsonSerializerContext.

View Source

SerializeAsync<T>(Stream, T, CancellationToken)

Serializes the specified object onto a stream.

Declaration
public abstract ValueTask SerializeAsync<T>(Stream stream, T obj, CancellationToken cancellationToken = default)
Parameters
Type Name Description
Stream stream

The stream to receive the serialized object.

T obj

The object to serialize.

CancellationToken cancellationToken

Cancellation token.

Returns
Type Description
ValueTask
Type Parameters
Name Description
T

Type of object to serialize.

View Source

Serialize<T>(IBufferWriter<byte>, T)

Serializes the specified object onto an IBufferWriter<T>.

Declaration
public abstract void Serialize<T>(IBufferWriter<byte> writer, T obj)
Parameters
Type Name Description
IBufferWriter<byte> writer

The writer to receive the serialized object.

T obj

The object to serialize.

Type Parameters
Name Description
T

Type of object to serialize.

View Source

Serialize<T>(Stream, T)

Serializes the specified object onto a stream.

Declaration
public abstract void Serialize<T>(Stream stream, T obj)
Parameters
Type Name Description
Stream stream

The stream to receive the serialized object.

T obj

The object to serialize.

Type Parameters
Name Description
T

Type of object to serialize.

View Source

Serialize<T>(Utf8JsonWriter, T)

Serializes the specified object onto a Utf8JsonWriter.

Declaration
public abstract void Serialize<T>(Utf8JsonWriter stream, T obj)
Parameters
Type Name Description
Utf8JsonWriter stream

The writer to receive the serialized object.

T obj

The object to serialize.

Type Parameters
Name Description
T

Type of object to serialize.

Implements

IExtendedTypeSerializer
IProjectableTypeDeserializer
IStreamingTypeDeserializer
IBufferedTypeSerializer
ITypeSerializer

Extension Methods

TypeSerializerExtensions.Deserialize<T>(ITypeSerializer, byte[], int, int)
TypeSerializerExtensions.Serialize(ITypeSerializer, object?)
  • View Source
In this article
Back to top Copyright © 2020 Couchbase, Inc. All rights reserved.