DataKernel features the fastest Serializer in the world! A bytecode generator of extremely fast and
space-efficient serializers, which are used for transferring data over wire or adding it into a file system or database.
Widely utilizes Codegen module.
Core Serializer features:
Implemented using runtime bytecode generation to be compatible with dynamically created classes (like intermediate
POJOs created with the Codegen module).
Stable binary format with backward binary compatibility for efficient long-term code support.
Support of the scheme evolution: changeable versions, added and removed fields, etc.
Full support of Java subclasses, collections (including Maps) and also specialized collections like HPPC.
Works directly with Java classes utilizing annotations. Thus, it doesn’t create additional layers of intermediate
DTO classes, which significantly speeds up the code and makes it easy-to-use.
Can be easily extended - you can write your own plugins for specific classes.
Includes special hints for even more efficient code (String formats, nullable, varlen, etc).
A common usage for Serializer is to pass some serialized class instances through the network to
remote machines for further processing. This approach is used in RPC,
LSM Tree OLAP Cube modules.
We’ve measured Serializer performance using this benchmark tool and
got the following results (compared to the second-fastest Java serializer Colfer):
You can add Serializer module to your project by inserting dependency in pom.xml:
To run the examples, you need to clone DataKernel from GitHub:
$ git clone https://github.com/softindex/datakernel And import it as a Maven project. Check out branch v3.1. Before running the examples, build the project.
These examples are located at datakernel -> examples -> core -> serializer
All of the examples consistently serialize and deserialize objects of different complexities.
Simple Object Serialization Example
If you run the Simple Object Serialization Example, you’ll get the following output:
The first column represents values of testData1, the second - of testData2. testData2 was
created with the help of serialization and deserialization of the testData1.
In order to create classes whose instances can be serialized/deserialized, special annotations should be used:
@Serialize annotation with order number on property getter. Ordering provides better compatibility in case
classes are changed.
@Deserialize annotation with property name (which should be the same name as the one in getter) in constructor.
@SerializeNullable on properties that can have null values.
Next, we need to create our BinarySerializer with the help of BinaryBuilder:
Generated bytecode of the BinarySerializer will be saved in your working directory.
An example of serialization and deserialization of a more complex object that contains nullable fields, map, list and a
two-dimensional array. If you run the example, you’ll receive the following output:
If you run the example, you’ll get the following output:
As you can see in the first line, dataObject2 differs from dataObject1. This is because @SerializeFixedSize
annotation was set at value 3 for the String array. Thus, “superfluous” was removed from the array while serialization took place: