Couchbase .NET SDK __CB_SDK_VERSION__

Show / Hide Table of Contents

Class DefaultSerializer

The default serializer for the Couchbase.NET SDK. Uses Newtonsoft.JSON as the the serializer.

Inheritance
object
DefaultSerializer
Implements
IExtendedTypeSerializer
IStreamingTypeDeserializer
IProjectableTypeDeserializer
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
public class DefaultSerializer : IExtendedTypeSerializer, IStreamingTypeDeserializer, IProjectableTypeDeserializer, IBufferedTypeSerializer, ITypeSerializer

Constructors

View Source

DefaultSerializer()

Declaration
[RequiresUnreferencedCode("The DefaultSerializer uses Newtonsoft.Json which requires unreferenced code and is incompatible with trimming.")]
[RequiresDynamicCode("The DefaultSerializer uses Newtonsoft.Json which requires dynamic code and is incompatible with AOT.")]
public DefaultSerializer()
View Source

DefaultSerializer(JsonSerializerSettings, JsonSerializerSettings)

Declaration
[RequiresUnreferencedCode("The DefaultSerializer uses Newtonsoft.Json which requires unreferenced code and is incompatible with trimming.")]
[RequiresDynamicCode("The DefaultSerializer uses Newtonsoft.Json which requires dynamic code and is incompatible with AOT.")]
public DefaultSerializer(JsonSerializerSettings deserializationSettings, JsonSerializerSettings serializerSettings)
Parameters
Type Name Description
JsonSerializerSettings deserializationSettings
JsonSerializerSettings serializerSettings

Fields

View Source

RequiresDynamicCodeMessage

Declaration
public const string RequiresDynamicCodeMessage = "The DefaultSerializer uses Newtonsoft.Json which requires dynamic code and is incompatible with AOT."
Field Value
Type Description
string
View Source

UnreferencedCodeMessage

Declaration
public const string UnreferencedCodeMessage = "The DefaultSerializer uses Newtonsoft.Json which requires unreferenced code and is incompatible with trimming."
Field Value
Type Description
string

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

DeserializationSettings

Gets the incoming de-serializer settings; controls the format of the incoming JSON for de-serialization into POCOs.

Declaration
public JsonSerializerSettings DeserializationSettings { get; }
Property Value
Type Description
JsonSerializerSettings

The incoming serializer settings.

View Source

SerializerSettings

Gets the outgoing serializer settings; controls the format of the JSON you are storing in Couchbase.

Declaration
public JsonSerializerSettings SerializerSettings { get; }
Property Value
Type Description
JsonSerializerSettings

The outgoing serializer settings; controls the format of the JSON you are storing in Couchbase.

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

CreateJsonStreamReader(Stream)

Create an IJsonStreamReader for parsing a Stream.

Declaration
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "This type may not be constructed without encountering a warning.")]
[UnconditionalSuppressMessage("Aot", "IL3050", Justification = "This type may not be constructed without encountering a warning.")]
public 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
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "This type may not be constructed without encountering a warning.")]
[UnconditionalSuppressMessage("Aot", "IL3050", Justification = "This type may not be constructed without encountering a warning.")]
public 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 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
[UnconditionalSuppressMessage("Aot", "IL3050", Justification = "This type may not be constructed without encountering a warning.")]
public 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 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
[UnconditionalSuppressMessage("Aot", "IL3050", Justification = "This type may not be constructed without encountering a warning.")]
public 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

GetDeserializationSettings(JsonSerializerSettings, DeserializationOptions?)

Declaration
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "This type may not be constructed without encountering a warning.")]
protected virtual JsonSerializerSettings GetDeserializationSettings(JsonSerializerSettings baseSettings, DeserializationOptions? options)
Parameters
Type Name Description
JsonSerializerSettings baseSettings
DeserializationOptions options
Returns
Type Description
JsonSerializerSettings
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.

Remarks

DefaultSerializer uses Newtonsoft.Json.JsonSerializerSettings.ContractResolver from SerializerSettings to determine the member name.

View Source

Serialize(Stream, object?)

Serializes the specified object onto a stream.

Declaration
public 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.

View Source

SerializeAsync(Stream, object?, CancellationToken)

Serializes the specified object onto a stream.

Declaration
public 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
View Source

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

Serializes the specified object onto an IBufferWriter<T>.

Declaration
public 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.

Implements

IExtendedTypeSerializer
IStreamingTypeDeserializer
IProjectableTypeDeserializer
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.