Comparison of three serialization methods in Java

Overview

Serialization is about converting an object into a byte stream, and deserialization is about converting a byte stream back to Java. Serialization is very efficient for storing and transferring objects. Three common serialization methods are discussed in the article

Java native serialization

After implementing the Serializable interface for the class to be serialized, deserialization and serialization can be achieved using ObjectInputStream and ObjectOutputStream.

Disadvantage: The least efficient of the three serialization methods.

JSON

Many JSON libraries, Google's GSON, Alibaba's FastJSON. Personally like to use FastJSON,
no need to write a bunch of Getters and Setters. It can read public properties

Advantages: Fast, readable, no special handling of the class to be serialized.

Google protobuf

The most efficient of the three methods. But some probuf configuration files are needed, describing how a class should be serialized. Using jProtobuf provided by baidu can simplify this process in the form of annotations.
https://github.com/jhunters/jprotobuf

Disadvantages: Requires configuration or annotation.
Advantages: The compression efficiency is very high. Extremely fast.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325518293&siteId=291194637