Serialization implements different Java serialization libraries into a pool to serialize or deserialize objects in byte arrays easily & quickly.
Creating a new SerializerPool
instance using standard JavaSerialization.class
:
SerializerPool pool = new SerializerPool(JavaSerialzation.class);
String string = new String("Lorem ipsum dolor sit amet.");
byte[] serialized = pool.serialize(string);
String deserialized = pool.deserialize(serialized);
If something goes wrong during de- or serialization, the exception is thrown and instead of the object you get null
.
Serialization (Class) | Serialization (Framework) |
---|---|
KryoSerialization |
Kryo |
KryoUnsafeSerialization |
Kryo |
JavaSerialization |
Java I/O |
FSTSerialization |
fast-serialization |
FSTNoSharedSerialization |
fast-serialization |
HessianSerialization |
Hessian |
Hessian2Serialization |
Hessian |
QuickserSerialization |
QuickSer |
ElsaSerialization |
Elsa |
ElsaStreamSerialization |
Elsa |
Frameworks:
Implementing a new Serialization
:
public class CustomSerialization implements Serialization {
@Override
public <T> byte[] serialize(T object) {
// Serialization workflow here
}
@Override
public <T> T deserialize(byte[] bytes) {
// Deserialization workflow here
}
}
Add repo.koboo.eu
as repository.
repositories {
maven { url 'https://repo.koboo.eu/releases' }
}
And add specific serializer as dependency. (e.g. 1.0
is the release-version)
dependencies {
// !Always needed!
compile 'eu.koboo:serial-core:1.0'
// Select specific serializer
compile 'eu.koboo:serial-elsa:1.0'
compile 'eu.koboo:serial-fst:1.0'
compile 'eu.koboo:serial-hessian:1.0'
compile 'eu.koboo:serial-kryo:1.0'
compile 'eu.koboo:serial-quickser:1.0'
}
- Clone repository
- Run
./gradlew buildApp
- Output
/build/libs/serialization-{version}-all.jar
- Build task build.gradle