Choosing the Right Java Serialization Library: Performance Benchmarks and Recommendations

This article surveys common Java serialization libraries, presents benchmark results on serialized size and speed for twelve implementations across seven primitive types, and offers practical guidance on selecting the most suitable serializer based on payload size, performance, and cross‑language requirements.

BanTech Think Tank
BanTech Think Tank
BanTech Think Tank
Choosing the Right Java Serialization Library: Performance Benchmarks and Recommendations

Overview

Serialization converts an object’s state into a storable or transmittable form, while deserialization rebuilds the object from the byte data. In Java, many open‑source components provide serialization, and several also support multiple languages for cross‑platform development.

Common Formats and Libraries

Java serialization formats are typically binary, JSON, XML, or other text formats. Common binary serializers include JDK native serialization, Protobuf, Kryo, Hessian, and Avro. JSON serializers include Jackson, FastJson, and Gson. XML serializers include JDK XML, Jakarta XML, and XStream. Additional options such as MsgPack, Thrift, Ion, and BSON are also available.

Performance Comparison

We evaluated twelve serializers: JDK, Jackson, FastJson, Gson, JDK XML, Jakarta XML, XStream, Kryo, Hessian, MsgPack, Avro, and Protobuf. The component versions are listed in Table 1. Seven primitive Java data types (Table 2) were used for testing.

Serialized size results (Table 3) show that Protobuf and Kryo produce the smallest payloads; MsgPack, Avro, Jackson, FastJson, and Gson generate moderate sizes; JDK, Jakarta XML, JDK XML, XStream, and Hessian produce larger payloads.

Serialization speed was measured by the total time of 10 000 serialize‑deserialize cycles per data type (Table 4). The fastest serializers are Protobuf, Avro, Hessian, FastJson, and JDK; Jackson, Gson, Kryo, and MsgPack have medium speed; Jakarta XML, JDK XML, and XStream are the slowest.

Deserialization speed (Table 5) indicates that Protobuf, Hessian, Avro, FastJson, and JDK are the quickest; Jackson, Gson, Kryo, and MsgPack are moderate; Jakarta XML, JDK XML, and XStream are the slowest.

Usage Recommendations

When payload size is critical, prefer binary serializers and avoid XML formats.

For high‑performance requirements, choose Protobuf, Hessian, Avro, or FastJson.

For cross‑platform or cross‑language scenarios, mature vendor solutions such as Google’s Protobuf are advisable.

When performance and size are comparable, select widely adopted libraries with active maintenance, e.g., Apache Avro or Google Protobuf.

If encryption, signing, or other special requirements are needed, define a custom serialization format and implement it yourself.

References

Jackson‑databind: https://github.com/FasterXML/jackson-databind

FastJson: https://github.com/alibaba/fastjson

FastJson2: https://github.com/alibaba/fastjson2

Gson: https://github.com/google/gson

Jakarta XML Binding: https://jakarta.ee/specifications/xml-binding/4.0/

XStream: https://x-stream.github.io/

Kryo: https://github.com/EsotericSoftware/kryo

Hessian: http://hessian.caucho.com/

MsgPack Java: https://github.com/msgpack/msgpack-java

Avro: https://github.com/apache/avro

Protobuf: https://github.com/protocolbuffers/protobuf

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaPerformanceserializationprotobufjsonhessianavrokryo
BanTech Think Tank
Written by

BanTech Think Tank

Tracks major fintech trends, focusing on fintech management, technology development, IT operations, information security, indigenous innovation, data governance, and business innovation. Aims to promote integrated industry‑academia‑research‑application development, offering a sharing platform for tech practitioners and valuable insights for institutional decision‑makers.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.