Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

efficient java object graph serialization

What is the best approach for serializing java object graphs?

My requirements for serialization library are 1) speed of deserialization 2) size - as small as possible (smaller than in java default serialization) 3) flexibility - annotation based definitions of what has to be serialized would be nice.

the underlying file format is not important.

I looked at Protocol Buffers and XStream, but the former is not flexible enough due to the need for mapping files and the later produces big files.

Any help appreciated.

like image 688
user87083 Avatar asked Apr 04 '09 13:04

user87083


2 Answers

For small objects, the Java serialised form is likely to be dominated by the description of the serialised classes.

You may be able to write out serialised data for commonly used classes, and then use that as a common prefix for a series of serialised streams. Note that this is very fragile, and you'll probably want to recompute and check it for each class loader instance.

like image 125
Tom Hawtin - tackline Avatar answered Sep 21 '22 04:09

Tom Hawtin - tackline


For serialization Hessian is one of the most efficient.

This is about 2-3 times smaller and faster than Java Serialization, even using Externalizable classes.

Whichever serialization you use, you can use compression fairly easily to make the data more compact.

Beyond that you can write your own serialization. I wrote a serializer which writes to/from ByteBuffer which is about twice as fast and half the size of Hessian (about 5x faster/smaller than Java Serialization) This may be too much effort for little gain if existing serializations will do what you need. However it is as customizable as you like ;)

like image 28
Peter Lawrey Avatar answered Sep 18 '22 04:09

Peter Lawrey