If possible, non-serializable parts can be installed as transitional
private transient SomeClass myClz;
Otherwise, you can use Kryo . Kryo is a fast and efficient object graph serialization structure for Java (for example, java.awt.Color JAVA serialization requires 170 bytes, Kryo only 4 bytes), which can also serialize non-serializable objects. Kryo can also perform automatic deep and shallow copying / cloning. This is a direct copy from object to object, not object->bytes->object .
Here is an example of using kryo
Kryo kryo = new Kryo(); // Restore from disk... Input input = new Input(new FileInputStream("file.bin")); SomeClass someObject = kryo.readObject(input, SomeClass.class); input.close();
Serialized objects can also be compressed by registering the exact serializer:
kryo.register(SomeObject.class, new DeflateCompressor(new FieldSerializer(kryo, SomeObject.class)));
Radim Burget Nov 12 '12 at 16:51 2012-11-12 16:51
source share