Class JsonExporter

Serializes MOSAIC pipeline configurations to JSON files.

Inheritance
JsonExporter
Namespace: MOSAIC.Components.Basics
Assembly: MOSAIC.dll
Syntax
public static class JsonExporter
Remarks

This class provides the inverse operation of JsonParser — it takes a collection of blocks and serializes them back to the standard JSON configuration format.

All blocks that inherit from BaseBlock automatically support JSON export via IJsonExportable. Derived blocks override GetJsonParams() to provide their specific parameters.

Blocks that do not implement IJsonExportable are silently skipped during export.

Property ordering: The exported JSON for each block follows a fixed property order: Type, DesiredRate, Inputs, Params, Path. SchemaVersion and Name are excluded because the block name serves as the dictionary key.

Fields

WriteOptions

Shared serializer options used for all JSON export operations.

Declaration
private static readonly JsonSerializerOptions WriteOptions
Field Value
Type Description
JsonSerializerOptions
Remarks

Configured with indented output, null-omission, no property name policy override, and a JsonStringEnumConverter for human-readable enum values.

Methods

BuildDictionary(IEnumerable<object>)

Builds an ordered export dictionary from a collection of blocks.

Declaration
private static Dictionary<string, object> BuildDictionary(IEnumerable<object> blocks)
Parameters
Type Name Description
IEnumerable<object> blocks

The block instances to export.

Returns
Type Description
Dictionary<string, object>

A dictionary mapping block names to their serializable property bags, with properties ordered as: Type, DesiredRate, Inputs, Params, Path.

Remarks

SchemaVersion and Name are excluded — the block name is used as the dictionary key.

Blocks that do not implement IJsonExportable or that have a null/empty Name are silently skipped.

SaveToFileAsync(IEnumerable<object>, string, CancellationToken)

Serializes a collection of blocks to a JSON configuration file.

Declaration
public static Task SaveToFileAsync(IEnumerable<object> blocks, string filePath, CancellationToken ct = default)
Parameters
Type Name Description
IEnumerable<object> blocks

The block instances to export. Only blocks implementing IJsonExportable are included.

string filePath

Destination file path. The file is overwritten if it already exists.

CancellationToken ct

Optional cancellation token forwarded to the file write operation.

Returns
Type Description
Task

A task that completes when the file has been written.

Exceptions
Type Condition
ArgumentNullException

Thrown if blocks or filePath is null.

IOException

Thrown if the file cannot be written.

Serialize(IEnumerable<object>)

Serializes a collection of blocks to a JSON string.

Declaration
public static string Serialize(IEnumerable<object> blocks)
Parameters
Type Name Description
IEnumerable<object> blocks

The block instances to export. Only blocks implementing IJsonExportable are included.

Returns
Type Description
string

A JSON string representing the pipeline configuration.

Exceptions
Type Condition
ArgumentNullException

Thrown if blocks is null.

Search documentation

Start typing to search the documentation.