Home United States USA — software High-Performance Java Serialization to Different Formats

High-Performance Java Serialization to Different Formats

170
0
SHARE

How to serialize and deserialize objects to and from a binary format, with higher performance than Java standard serialization
Join the DZone community and get the full member experience. Java serialization is a popular mechanism where you are able to serialize and deserialize complex object graphs; for example where object A can contain a reference to object B, which in turn has a reference back to object A. The problem is that this rich functionality comes at a performance cost. However, if you do not need to serialize these types of recursive graphs, you can instead use an Open Source solution called Chronicle Wire. It has reduced complexity and uses tree-like structures which makes it very efficient. Moreover, it can be done in a lot of different formats with no need to change the coding. This article covers the basics of serialization and discusses some of the key advantages of Chronicle Wire. Serialization is about encoding java objects into bytes, for example, we have an object. Let’s say our object holds our application state, if we were to shut down our application we would lose the state, we want to first store our application’s state to disk, so we serialize our java state object. This will convert the object into bytes, which can be easily stored. Likewise, If we want to send the data stored in our java object, over the network, we first have to serialize the object, before it can be written to the TCP/IP buffer. Deserialization is the opposite of serialization, where we start with a byte and recreate an object instance. Chronicle Wire is an open-source library that was originally written to support Chronicle Queue and Chronicle Map. However, the library is useful in any code that uses serialization. Chronicle Wire differs from native Java serialization in that it actually supports a number of different formats, for example, binary, YAML, JSON, raw binary data, and CSV. The real innovation behind Chronicle Wire is that you don’t have to change your code to change the encoding. The library abstracts away the implementation of the serialization to a pluggable Wire implementation. The idea is that your objects need only describe what is to be serialized not how it should be serialized. This is done by the objects (the POJOs that are to be serialized) implementing the Marshallable interface. “net.openhft.chronicle.wire. Marshallable” (When you use the Java Serialization you add the marker interface on “java.

Continue reading...