Table of Contents

Class CachedValueJsonConverter

Namespace
Excalibur.Dispatch.Caching
Assembly
Excalibur.Dispatch.Caching.dll

Custom JSON converter for CachedValue that handles polymorphic serialization of the Value property using the TypeName field.

public sealed class CachedValueJsonConverter : JsonConverter<CachedValue>
Inheritance
CachedValueJsonConverter
Inherited Members
Extension Methods

Remarks

AOT / Trimming Behavior: This converter uses runtime type-name resolution and Deserialize(string, Type, JsonSerializerOptions) to reconstruct typed values from their serialized form. In AOT or trimmed environments, type resolution may fail if the target type is not preserved. When this occurs, the Value property falls back to a JsonElement representation, preserving the raw JSON data without throwing. Consumers should check for JsonElement as a fallback type when running in AOT scenarios.

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to type CachedValue.

[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with RequiresUnreferencedCodeAttribute may break with trimming", Justification = "Reconstructing a cached value by its stored type name is what this converter is for, so the requirement cannot be removed here. It is not hidden from the consumer: a converter runs only inside a JsonSerializer call, and those overloads carry the same annotation at the consumer's own call site.")]
[UnconditionalSuppressMessage("Aot", "IL3050:Calling members annotated with RequiresDynamicCodeAttribute may break functionality when AOT compiling.", Justification = "Serializing a cached value by its runtime type is what this converter is for, so the requirement cannot be removed here. It is not hidden from the consumer: a converter runs only inside a JsonSerializer call, and those overloads carry the same annotation at the consumer's own call site.")]
public override CachedValue? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

Parameters

reader Utf8JsonReader

The reader.

typeToConvert Type

The type to convert.

options JsonSerializerOptions

An object that specifies serialization options to use.

Returns

CachedValue

The converted value.

Write(Utf8JsonWriter, CachedValue, JsonSerializerOptions)

Writes a specified value as JSON.

[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with RequiresUnreferencedCodeAttribute may break with trimming", Justification = "Reconstructing a cached value by its stored type name is what this converter is for, so the requirement cannot be removed here. It is not hidden from the consumer: a converter runs only inside a JsonSerializer call, and those overloads carry the same annotation at the consumer's own call site.")]
[UnconditionalSuppressMessage("Aot", "IL3050:Calling members annotated with RequiresDynamicCodeAttribute may break functionality when AOT compiling.", Justification = "Serializing a cached value by its runtime type is what this converter is for, so the requirement cannot be removed here. It is not hidden from the consumer: a converter runs only inside a JsonSerializer call, and those overloads carry the same annotation at the consumer's own call site.")]
public override void Write(Utf8JsonWriter writer, CachedValue value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The writer to write to.

value CachedValue

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.