Introduction
This is the Java flavor of NxSerialization for CLR (.NET and Mono) that is an easy to use object serialization framework that replaces the functionality of the default serialization providers. For background information, read this article http://www.codeproject.com/KB/dotnet/OpenNxSerialization.aspx.
Quick Facts
The figure below contains the benchmark results using the sample application shipped with NxSerialization for Java. The time measured was for 100 iterations of 100 runs each. In each run, an object of the specified type was serialized and then deserialized. These results may vary depending upon the system configuration; however, the important thing to consider is the relative difference or the performance factors between the native and the NxSerializer.
Performance comparison of native and NxSerialization formatters
Why a Java version?
There were no plans to release a Java version of NxSerializatio, because unlike .NET and Mono, the native serializer for Java performs quite well. NxSerialization for Java was written primarily for two purposes. Firstly, as a proof of concept that even Java native serialization can be improved upon. Secondly, and more importantly, it serves as a launch pad for portable binary serialization; a project that is next in the pipeline.
However, since that project is still far from realization, and based upon popular demand, NxSerialization for Java has been released for review. Expectations are not very high from this release, but it would still be good to hear some suggestions and know that someone actually found it useful.
Using the Framework
Application objects can be integrated with the framework in two ways. By writing a surrogate for the object type and registering the surrogate with the framework, or by implementing INxSerializable
. The framework provides a built-in surrogate for types that implement INxSerializable
. For unknown types, native .NET serialization is used.
The following sample of code demonstrates a type that implements INxSerializable
. Note the line at the bottom that registers the type with the framework.
NxFormatterServices services = NxFormatterServices.getDefault();
services.registerKnownType(SampleClass.class);
services.getSurrogateSelector().register(new SampleSurrogate());
ObjectOutput writer = NxObjectOutputStream(new ByteArrayOutputStream());
writer.writeObject(sampleGraph);
writer.flush();
byte[] contents = writer.getBaseStream().toByteArray();
ObjectInput reader = NxObjectInputStream(new ByteArrayInputStream(contents));
Object read = reader.readObject();
Everything else is pretty much self-explanatory. For more information, look at the sample benchmark application provided with the source code.
Comments
Please note that for objects where the actual data size to type-info size ratio is very large, not much memory reduction will occur. Try a byte
array of size 100K. It is also possible to come up with a case where the native serializer is actually more efficient in terms of CPU.
History
OpenNxSerialization 1.0 (June 15, 2009)
- Released the initial version of the framework.