Fast and compact serialization of Java object.
- Concrete Collections (Map, Set, Vector, List) with compression/decompression using Snappy
- Primitive types: int, long, short, double, float, boolean, char, byte, enum
- Primitive array: with compression/decompression using Snappy
- Time types: Date, LocalDate, LocalTime, LocalDateTime, Instant, Duration, Period, MonthDay, Year
- Other types are serialized using Java's default serialization
Use the provided static methods to serialize and/or deserialize your object(s). There is two ways:
- Raw serialization: the fastest
- Compressed serialization: slower but more compact
The serialization used our Snappy based specialized compressors.
import java.io.*;
import com.qwazr.externalizor.Externalizor;
public class FastSerialization {
public FastSerialization() {
MyClass object = new MyClass();
byte[] bytes;
// Serialization
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
Externalizor.serializeRaw(object, output);
bytes = output.toByteArray();
}
// Deserialization
try (ByteArrayInputStream input = new ByteArrayInputStream(bytes)) {
MyClass object = Externalizor.deserializeRaw(input);
}
}
}
In addition of the specialized compression (snappy) a GZIP compression is used on the final serialized stream (slower but more compact).
import java.io.*;
import com.qwazr.externalizor.Externalizor;
public class CompactSerialization {
public CompactSerialization() {
MyClass object = new MyClass();
byte[] bytes;
// Serialization
try (ByteArrayOutputStream input = new ByteArrayOutputStream()) {
Externalizor.serialize(object, output);
bytes = output.toByteArray();
}
// Deserialization
try (ByteArrayInputStream input = new ByteArrayInputStream(bytes)) {
object = Externalizor.deserialize(input);
}
}
}
In Maven's central repository: central.maven.org/maven2/com/qwazr/externalizor
Add the following dependency to your pom.xml:
<dependency>
<groupId>com.qwazr</groupId>
<artifactId>externalizor</artifactId>
<version>1.3.2</version>
</dependency>
The code of the benchmark is here: BenchmarkTest
- Serialization raw: Default Java serialization without compression.
- Serialization compressed: Default Java serialization with Gzip compression.
- Externalizor raw: Using Externalizor without compression.
- Externalizor compressed: Using Externalizor with Gzip compression.
Bytes sizes. Smaller is better.
Number of serialization and deserialization per seconds. Bigger is better.
Post bug reports or feature request to the Issue Tracker: https://github.com/qwazr/externalizor/issues