Class ObjectListConverter

Custom JSON converter that preserves JsonElement instances for mixed-type arrays.

Inheritance
ObjectListConverter
Namespace: MOSAIC.Components.Basics
Assembly: MOSAIC.dll
Syntax
public class ObjectListConverter : JsonConverter<IReadOnlyList<object>?>
Remarks

This converter is applied to Params to support heterogeneous parameter lists (numbers, strings, booleans, nested objects, etc.) without losing type information during deserialization.

On read, each array element is parsed as a JsonElement and stored in the list. On write, JsonElement values are written directly; all other types fall back to Serialize(Utf8JsonWriter, object, Type, JsonSerializerOptions).

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads a JSON array and deserializes each element as a JsonElement.

Declaration
public override IReadOnlyList<object>? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
Type Name Description
Utf8JsonReader reader

The UTF-8 JSON reader to consume tokens from.

Type typeToConvert

The target type (always IReadOnlyList<T>).

JsonSerializerOptions options

Serializer options forwarded by the framework.

Returns
Type Description
IReadOnlyList<object>

A list of JsonElement values, or null if the JSON token is null.

Overrides
JsonConverter<IReadOnlyList<object>>.Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Exceptions
Type Condition
JsonException

Thrown when the current token is neither Null nor StartArray.

Write(Utf8JsonWriter, IReadOnlyList<object>?, JsonSerializerOptions)

Writes a list of objects as a JSON array, preserving JsonElement values natively.

Declaration
public override void Write(Utf8JsonWriter writer, IReadOnlyList<object>? value, JsonSerializerOptions options)
Parameters
Type Name Description
Utf8JsonWriter writer

The UTF-8 JSON writer to emit tokens to.

IReadOnlyList<object> value

The list to serialize, or null to emit a JSON null.

JsonSerializerOptions options

Serializer options forwarded by the framework.

Overrides
JsonConverter<IReadOnlyList<object>>.Write(Utf8JsonWriter, IReadOnlyList<object>, JsonSerializerOptions)

Search documentation

Start typing to search the documentation.