Main Page | See live article | Alphabetical index

Java serialization

Java provides automatic serialization which only requires that the object be marked by implementing the Serializable interface. For some not-so-clear reason, the process of serialization is handled in a very idiosyntric manner. There are no serialization methods defined on the Serializable interface; implementing the interface just marks the class as "okay to serialize." Java then handles serialization internally, though it does allow the developer to override this by implementing two special methods on a Serializable object. Again, these methods are not defined on the Serializable interface.

The standard encoding method uses a simple transaltion of the fields into a byte stream. Primitives as well as referenced objects are encoded into the stream. Each object that is referenced by the serialized object must also be serialized and if any in the reference graph is not Serializable, then serialization will fail (unless the developer has redefined the serialization for an object and truncates some portion of the reference graph).

There is a push to redefine, or provide an alternative to the standard serialization protocol that uses XML and produces a human readable encoding. Such an encoding could be useful for persisted objects that may be browsed by humans or communicated to other, non-Java systems, but the more compact, byte encoding is generally more practical.