alexa
menu

MAUI

  • User Guide
  • Demos
  • Support
  • Forums
  • Download

    Show / Hide Table of Contents

    Class DiagramStateSerializer

    Serializes Nodes/Connectors to a JSON document that can be written to disk and later reloaded, and reconstructs them back into live model objects. Powers Syncfusion.Maui.Diagram.SfDiagram.GetDiagramState(System.Boolean)/LoadDiagram(String), and can also be called directly if you want the JSON without touching SfDiagram at all (for example, to save it from a background thread, or unit-test a round trip).

    Inheritance
    System.Object
    DiagramStateSerializer
    Namespace: Syncfusion.Maui.Diagram
    Assembly: Syncfusion.Maui.Diagram.dll
    Syntax
    public static class DiagramStateSerializer : Object
    Remarks

    This is a deliberately separate JSON shape from the one Json/*Converter classes (NodeJsonConverter, ConnectorJsonConverter, etc.) produce. Those converters have one job: mirror the exact EJ2 Diagram NodeModel/ConnectorModel wire format the hosted JavaScript expects, which is why every one of them is write-only (see each converter's own Read override) — they were never meant to be read back, only sent. Reusing that wire format for persistence would also lose real information on the round trip: EJ2's ConnectorModel annotation shape (PathAnnotationModel) only has a single 0–1 offset and a 3-way "Before"/"Center"/"After" alignment string, so a connector Annotation's OffsetY and its full AnnotationHorizontalAlignment/ AnnotationVerticalAlignment pair would be silently narrowed every time you saved. The shape here instead mirrors each model class's own properties directly and identically for both node and connector annotations, so a save/load round trip is fully lossless — at the cost of not being valid input to send straight to the JavaScript side (which is fine: nothing here needs to be).

    Methods

    Deserialize(String)

    Parses json (as produced by Serialize(IEnumerable<Node>, IEnumerable<Connector>, Boolean)) back into live Node/Connector instances, with every id preserved exactly as saved — including SourceID/TargetID/SourcePortID/ TargetPortID references between them, which only resolve correctly if node ids are reused rather than regenerated. The returned nodes/connectors aren't attached to any SfDiagram yet — add them to Nodes/Connectors yourself, or just call LoadDiagram(String) instead, which does that (replacing whatever was there before) in one step.

    Declaration
    public static DiagramState Deserialize(string json)
    Parameters
    Type Name Description
    System.String json
    Returns
    Type
    DiagramState
    Exceptions
    Type Condition
    System.Text.Json.JsonException

    json isn't well-formed JSON, or is missing the top-level "nodes"/"connectors" arrays entirely. Anything narrower than that (a missing or unrecognized field on one particular node/connector/style) falls back to that property's normal model default instead of throwing, so a hand-edited or slightly-older save file degrades gracefully rather than failing the whole load.

    Serialize(IEnumerable<Node>, IEnumerable<Connector>, Boolean)

    Serializes nodes and connectors to a JSON string.

    Declaration
    public static string Serialize(IEnumerable<Node> nodes, IEnumerable<Connector> connectors, bool indented = true)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<Node> nodes

    The nodes to serialize, in order.

    System.Collections.Generic.IEnumerable<Connector> connectors

    The connectors to serialize, in order.

    System.Boolean indented

    Whether to pretty-print the result (the default) — purely cosmetic, for a save file a person might open directly; set false for the most compact output.

    Returns
    Type
    System.String
    Back to top Generated by DocFX
    Copyright © 2001 - 2026 Syncfusion Inc. All Rights Reserved