Serializer module is a bytecode generator of extremely fast and space efficient serializers, which are used for
transferring data over wire or persisting it into a file system or database.
Schema-less approach for maximum performance and compactness (unlike other serializers, there is no overhead
in typed values)
Implemented using runtime bytecode generation, to be compatible with dynamically created classes (like intermediate
POJOs created with Codegen module)
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.
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. Before running the examples, build the project.
All of the examples consistently serialize and deserialize objects of different complexity.
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 same as 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 BinarySerializer will be saved in your working directory.
Complex Object Serialization Example is an example of serialization and deserialization of a more complex object,
which contains nullable fields, map, list and a two-dimensional array. If you run the example, you’ll receive the
If you run Fixed Size Fields Serialization 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: