快速序列化Java开源库,Fast-serialization 2.18 发布
FST fast-serialization重新实现的Java序列化,注重速度,大小和兼容性。使用FST代替原有功能,只需要修复很少的代码。
项目地址:http://ruedigermoeller.github.io/fast-serialization/
特性:
- Faster serialization and smaller object size.
- drop-in replacement. Does not require special getters/setters/Constructors/Interfaces to serialize a class. Extends Outputstream, implements
ObjectInput/ObjectOutput
. Few code changes required. - Full support of JDK-serialization features such as Externalizable writeObject/readObject/readReplace/validation/putField/getField, hooks etc.. If an object is serializable with JDK, it should be serializable with FST without any further work.
- preserves links inside the serialized object graph same as JDK default serialization
- custom optimization using annotations, custom serializers
- supports versioning (2.x only)
- conditional decoding (skip decoding parts of an object/stream in case)
支持 java 1.7+ (fst 1.62: JDK 1.6)
- fst 1.x is jdk 1.6 compatible (no use of 1.7 features). I backport 2.x fixes from time to time or upon request
- FST-structs does require 1.7 API
示例:
// ! reuse this Object, it caches metadata. Performance degrades massively // if you create a new Configuration Object with each serialization ! static FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration(); ... public MyClass myreadMethod(InputStream stream) throws IOException, ClassNotFoundException { FSTObjectInput in = conf.getObjectInput(stream); MyClass result = in.readObject(MyClass.class); // DON'T: in.close(); here prevents reuse and will result in an exception stream.close(); return result; } public void mywriteMethod( OutputStream stream, MyClass toWrite ) throws IOException { FSTObjectOutput out = conf.getObjectOutput(stream); out.writeObject( toWrite, MyClass.class ); // DON'T out.close() when using factory method; out.flush(); stream.close(); }
FST 2.18 发布了,从 2.17 版本开始 FST 的许可证由原来的 LGPL 改为 Apache。
与 2.16 版本比较,其他改进包括:
Wavesonics contributed an android port (only plain serialization tested). Merged this to keep a single branch. For android a different object instantiation strategy is used. Adds a dependency to objenesis-2.1
fixed 2.x structs (for fast-cast 3.0). Had some issues because of low test coverage. Writing unit tests for structs still open.
Bug 修复:
changes done from 1.x to 2.x introduced an unnecessary perf degradation when reading from byte[]. Affects small objects most. fixed.
kson supports thousand separator in numbers '_'
fixed stackoverflow on some android devices with smallish stack sizes
fixed a buffer overflow reading externalizables when using fastBinaryConfiguration