Table of Contents

Class SystemJsonSerializer

Namespace
Akavache.SystemTextJson
Assembly
Akavache.SystemTextJson.dll

A unified serializer using System.Text.Json with automatic format detection. Supports both JSON and BSON formats for maximum compatibility.

public class SystemJsonSerializer : ISerializer
Inheritance
SystemJsonSerializer
Implements
Derived
Extension Methods
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>, bool)

Constructors

SystemJsonSerializer()

public SystemJsonSerializer()

Properties

ForcedDateTimeKind

Gets or sets the DateTimeKind handling for BSON readers to be forced.

public DateTimeKind? ForcedDateTimeKind { get; set; }

Property Value

DateTimeKind?

Remarks

By default, BsonReader uses a DateTimeKind of Local and see BsonWriter uses Utc. Thus, DateTimes are serialized as UTC but deserialized as local time. To force BSON readers to use some other DateTimeKind, you can set this value.

Options

Gets or sets the JSON serializer options for customizing serialization behavior.

public JsonSerializerOptions? Options { get; set; }

Property Value

JsonSerializerOptions

UseBsonFormat

Gets or sets a value indicating whether to use BSON format for serialization. When true, serializes to BSON for maximum Akavache compatibility. When false (default), serializes to JSON for better performance.

public bool UseBsonFormat { get; set; }

Property Value

bool

Methods

Deserialize<T>(byte[])

Deserializes from bytes.

[RequiresUnreferencedCode("Using System.Text.Json requires types to be preserved for deserialization.")]
[RequiresDynamicCode("Using System.Text.Json requires types to be preserved for deserialization.")]
public T? Deserialize<T>(byte[] bytes)

Parameters

bytes byte[]

The bytes.

Returns

T

The type.

Type Parameters

T

The type to deserialize to.

IsPotentialBsonData(byte[])

Checks if data might be BSON format.

public static bool IsPotentialBsonData(byte[] data)

Parameters

data byte[]

The data to check.

Returns

bool

True if data might be BSON.

Serialize<T>(T)

Serializes to an bytes.

[RequiresUnreferencedCode("Using System.Text.Json requires types to be preserved for serialization.")]
[RequiresDynamicCode("Using System.Text.Json requires types to be preserved for serialization.")]
public byte[] Serialize<T>(T item)

Parameters

item T

The item to serialize.

Returns

byte[]

The bytes.

Type Parameters

T

The type of serialize.