Class ObjectListConverter
Custom JSON converter that preserves JsonElement instances for mixed-type arrays.
Inherited Members
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 |
Overrides
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 |
| JsonSerializerOptions | options | Serializer options forwarded by the framework. |