Class Yggdrasil

java.lang.Object
ch.njol.yggdrasil.Yggdrasil

@NotThreadSafe public final class Yggdrasil extends Object
Yggdrasil is a simple data format to store object graphs.

Yggdrasil uses String IDs to identify classes, thus all classes to be (de)serialized have to be registered to Yggdrasil before doing anything (they can also be registered while Yggdrasil is working, but you must make sure that all classes are registered in time when deserializing). A ClassResolver or YggdrasilSerializer can also be used to find classes and IDs dynamically.

Default behaviour

A Java object can be serialized and deserialized if it is a primitive, a primitive wrapper, a String, an enum or PseudoEnum (both require an ID), or its class meets all the following requirements:

  • It implements YggdrasilSerializable
  • It has an ID assigned to it (using the methods described above)
  • It provides a nullary constructor (any access modifier) (in particular anonymous and non-static inner classes can't be serialized)
  • All its non-transient and non-static fields are serializable according to these requirements

Yggdrasil will generate errors if an object loaded either has too many fields and/or is missing some in the stream.

Customisation

Any object that does not meet the above requirements for serialisation can still be (de)serialized using an YggdrasilSerializer (useful for objects of an external API), or by implementing YggdrasilSerializable.YggdrasilExtendedSerializable.

The behaviour in case of an invalid or outdated stream can be defined likewise, or one can implement YggdrasilSerializable.YggdrasilRobustSerializable or YggdrasilSerializable.YggdrasilRobustEnum respectively.