documentationfor yFiles for HTML 2.6

Automatically Serialized Types

The I/O mechanism in yFiles for HTML is designed to serialize objects where possible without the need of custom serialization code. Here’s a list of types that can be (de)serialized automatically:

  • Primitive data types (boolean, string, number)
  • Enums
  • JSON-serializable values:
    • For these the JSON representation will be embedded resp. parsed in/from the GraphML
  • Classes that follow these rules:
    • They provide a public default constructor (without arguments)
    • All their relevant properties are readable and writable.
    • They are yFiles for HTML classes, i.e. they are created using Class<T> or ClassDefinition, or extend one of them.
    • There must exist a mapping between the type and the fully qualified element name. When using a markup extension, both the markup extension type and the represented type must be mapped.

So you don’t need to worry about serializing them. The graph I/O mechanism is able to build Objects that follow the above mentioned rules via reflection automatically.

Design your custom data with automatic serializability in mind.

Map the Namespace of Your Custom Types

Custom data consisting of structured types that is serialized by the default XML serialization support of yFiles for HTML must be given a custom XML namespace by means of a namespace mapping. The mapping for a type to an XML namespace and XML tag name is defined by registering a namespace mapping to GraphMLIOHandler.

The following example shows how to define an XML namespace mapping:

graphMLIOHandler.addXamlNamespaceMapping(
  'http://www.yworks.com/xml/yfiles-for-html/orgchart/1.0',
  'Employee',
  Employee.$class
)

The XML namespace should be a unique namespace URI that is ideally owned by the application developer. It does not have to point to an existing or valid document URL. Optimally, it includes a version number.

It is also possible to register multiple types at once with the module overload of addXamlNamespaceMapping. It accepts an object with keys as XML tag names and values as types.

graphMLIOHandler.addXamlNamespaceMapping('http://www.yworks.com/xml/yfiles-for-html/orgchart/1.0', {
  Employee: Employee,
  Department: Department
})