高效的java对象图序列化 [英] efficient java object graph serialization

查看:41
本文介绍了高效的java对象图序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

序列化 Java 对象图的最佳方法是什么?

What is the best approach for serializing java object graphs?

我对序列化库的要求是1)反序列化的速度2)大小 - 尽可能小(小于java默认序列化)3) 灵活性 - 基于注释的必须序列化的定义会很好.

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.

我看了Protocol Buffers和XStream,但前者不够灵活,因为需要映射文件,后者产生大文件.

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.

感谢任何帮助.

推荐答案

对于序列化 Hessian 是最有效的之一.

For serialization Hessian is one of the most efficient.

即使使用 Externalizable 类,这也比 Java 序列化小 2-3 倍,速度也快.

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.

除此之外,您还可以编写自己的序列化.我写了一个序列化程序,它向/从 ByteBuffer 写入,它的速度大约是 Hessian 的两倍,大小是 Hessian 的一半(大约比 Java 序列化快 5 倍/小)如果现有的序列化可以满足您的需求,这可能会付出太多努力而收获甚微.但是,它可以根据您的喜好进行自定义;)

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 ;)

这篇关于高效的java对象图序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆