Serenity is a fast serialization library for Java which supports all Java Primitives,Objects , Strings, Arrays , List and offers many performance benefits over the default Java Serialization implementation.
-
Build the project by taking a clone of main branch and using java 17 so that all the dependencies are downloaded.
-
Once the jar is installed, use this jar as dependency in your project.
-
To use the serialization just invoke writeObjectAsBytes method using Serenity Object in your project. Here is an example of the same.
Serenity serenity = new Serenity();
byte[] byteArray = serenity.writeObjectAsBytes(objectToBeSerialized);- Serenity reads all the non-final fields declared in the class and converts them into custom classes. Once all the custom classes are created for all the fields, it then converts them into bytes and return a byte array.
One more implementation that mimics the jackson reading of fields in the class, that is using getter methods. This is used to solve the problem of unnecessary reading of fields that are not required for serialization, but downside is that it significantly impacts the performance of the Serenity.
Serenity serenity = new Serenity();
byte[] byteArray = serenity.writeObjectAsBytesUsingMethods(objectToBeSerialized);When compared with java serialization, it has significant improvement upto 50% less time taken for serializing the same size object. Even coming close to almost equal compared to json serialization(the god of serialization). This is a graph of time taken in microseconds by 3 serialization methods when the object size is increased upto 200KB.
Further progress can be made in these areas:-
- There is a scope for improvement in the time taken by Serenity by reducing the number of duplicate custom objects created by the system
- Serenity cannot handle other collections other than List, so that is a big area which asks for improvement
- field annotations can be added just like in jackson to give more flexibility in creation of serialization objects.

