Table of Contents

Class GraphSerializer

Namespace
FlowGraph.Core.Serialization
Assembly
FlowGraph.Core.dll

Serializes and deserializes graphs to/from JSON.

public static class GraphSerializer
Inheritance
GraphSerializer
Inherited Members

Remarks

Supports two format versions:

  • Version 2 (default): Uses polymorphic elements[] array with "kind" discriminator
  • Version 1 (legacy): Uses separate nodes[], edges[], shapes[] arrays

Serialization always outputs Version 2 format. Deserialization supports both formats for backward compatibility with older saved files.

Methods

Deserialize(string, JsonSerializerOptions?)

Deserializes a graph from a JSON string.

public static Graph? Deserialize(string json, JsonSerializerOptions? options = null)

Parameters

json string

JSON string to deserialize.

options JsonSerializerOptions

Optional JSON serializer options. Uses default if not specified.

Returns

Graph

Deserialized graph, or null if deserialization fails.

DeserializeFromFileAsync(string, JsonSerializerOptions?)

Deserializes a graph from a JSON file.

public static Task<Graph?> DeserializeFromFileAsync(string filePath, JsonSerializerOptions? options = null)

Parameters

filePath string

Path to the JSON file.

options JsonSerializerOptions

Optional JSON serializer options. Uses default if not specified.

Returns

Task<Graph>

Deserialized graph, or null if deserialization fails.

Serialize(Graph, JsonSerializerOptions?)

Serializes a graph to a JSON string.

public static string Serialize(Graph graph, JsonSerializerOptions? options = null)

Parameters

graph Graph

The graph to serialize.

options JsonSerializerOptions

Optional JSON serializer options. Uses default if not specified.

Returns

string

JSON string representation of the graph.

SerializeToFileAsync(Graph, string, JsonSerializerOptions?)

Serializes a graph to a JSON file.

public static Task SerializeToFileAsync(Graph graph, string filePath, JsonSerializerOptions? options = null)

Parameters

graph Graph

The graph to serialize.

filePath string

Path to the output file.

options JsonSerializerOptions

Optional JSON serializer options. Uses default if not specified.

Returns

Task

TryValidate(string, out string?)

Validates JSON without fully deserializing.

public static bool TryValidate(string json, out string? errorMessage)

Parameters

json string

JSON string to validate.

errorMessage string

Error message if validation fails, null otherwise.

Returns

bool

True if JSON is valid, false otherwise.