Search
Serializing the Diagram

JSON Serialization

To serialize a diagram as a JSON string, call its SaveToJson method. To deserialize a diagram back from its JSON representation, call the LoadFromJson method. The SaveToJsonFile and LoadFromJsonFile methods serialize the JSON strings to / from files.

Custom item classes can implement JSON serialization for their additional properties by overriding the SaveToJson and LoadFromJson methods. Such classes must be registered for serialization by calling the RegisterItemClass method and providing a string identifier for the clientClass parameter.

The control raises JsonSerializeTag and JsonDeserializeTag to enable serialization of complex Id and Tag objects without overriding the item classes. The PropertyName event argument specifies which property is being serialized.

JSON serialization is handled internally by the classes from MindFusion.Json namespace. The JsonValue class represents a property value. Property names and values are stored in instances of the JsonObject dictionary class. The JsonContext class handles the serialization of the Diagram properties. The Serialize method is a wrapper over the Serializer class' Serialize method. It takes a JsonObject and serializes it to a string. The Parse method is a wrapper over the Parser class' ReadJsonObject method. It takes a JSON-formatted string and returns a JsonObject with the parsed data.

XML Serialization

It is possible to save a diagram as an XML document. To do that, call the SaveToXml method of the Diagram class. To deserialize a diagram back from its XML representation, call the LoadFromXml method.

Custom item classes can implement XML serialization for their additional properties by overriding the SaveToXml and LoadFromXml methods. In addition, such classes must specify a string to use as their identifier in the XML document by calling RegisterItemClass.

The control raises SerializeTag and DeserializeTag to enable serialization of complex Id and Tag objects without overriding the item classes. The PropertyName event argument specifies which property is being serialized.