Skip to content

SystemTextJsonVitreousCacheSerializer class

Namespace: Vitreous.Caching.Serialization
Assembly: Vitreous.Caching.dll

Default IVitreousCacheSerializer, backed by System.Text.Json.

public sealed class SystemTextJsonVitreousCacheSerializer : IVitreousCacheSerializer

object ← SystemTextJsonVitreousCacheSerializer

IVitreousCacheSerializer

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Values are stored in an envelope that records the result type:

{ "t": "MyApp.OrderDto", "v": { ...the value... } }

Reading an entry written for another type, or in an older format, is reported as a miss.

System.Text.Json only round-trips what it can serialize: get-only properties without a matching constructor parameter come back with default values. Use types with settable properties or a matching constructor (records are fine), or supply [JsonSerializerOptions](https://learn.microsoft.com/dotnet/api/system.text.json.jsonserializeroptions) / a custom serializer that handles your types.

Trimmed and Native AOT apps must pass options whose [TypeInfoResolver](https://learn.microsoft.com/dotnet/api/system.text.json.jsonserializeroptions.typeinforesolver) is a [JsonSerializerContext](https://learn.microsoft.com/dotnet/api/system.text.json.serialization.jsonserializercontext) that includes every cached result type.

SystemTextJsonVitreousCacheSerializer(JsonSerializerOptions?)

Section titled “ SystemTextJsonVitreousCacheSerializer(JsonSerializerOptions?)”

Creates a serializer using options, or camelCase defaults when null.

public SystemTextJsonVitreousCacheSerializer(JsonSerializerOptions? options = null)

options JsonSerializerOptions?

Serializes value, recording that it is a T.

public byte[] Serialize<T>(T value)

value T

byte[]

T

TryDeserialize<T>(ReadOnlySpan<byte>, out T?)

Section titled “ TryDeserialize<T>(ReadOnlySpan<byte>, out T?)”

Deserializes data as a T. Returns false when the data holds a different type or an unrecognised format; callers treat that as a cache miss.

public bool TryDeserialize<T>(ReadOnlySpan<byte> data, out T? value)

data ReadOnlySpan<byte>

value T?

bool

T