SystemTextJsonVitreousCacheSerializer class
Namespace: Vitreous.Caching.Serialization
Assembly: Vitreous.Caching.dll
Default IVitreousCacheSerializer, backed by System.Text.Json.
public sealed class SystemTextJsonVitreousCacheSerializer : IVitreousCacheSerializerInheritance
Section titled “Inheritance”object ← SystemTextJsonVitreousCacheSerializer
Implements
Section titled “Implements”Inherited Members
Section titled “Inherited Members”object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
Section titled “Remarks”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.
Constructors
Section titled “Constructors”SystemTextJsonVitreousCacheSerializer(JsonSerializerOptions?)
Section titled “ SystemTextJsonVitreousCacheSerializer(JsonSerializerOptions?)”Creates a serializer using options, or camelCase defaults when
null.
public SystemTextJsonVitreousCacheSerializer(JsonSerializerOptions? options = null)Parameters
Section titled “Parameters”options JsonSerializerOptions?
Methods
Section titled “Methods”Serialize<T>(T)
Section titled “ Serialize<T>(T)”Serializes value, recording that it is a T.
public byte[] Serialize<T>(T value)Parameters
Section titled “Parameters”value T
Returns
Section titled “Returns”byte[]
Type Parameters
Section titled “Type Parameters”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)Parameters
Section titled “Parameters”data ReadOnlySpan<byte>
value T?
Returns
Section titled “Returns”Type Parameters
Section titled “Type Parameters”T