On the difference between Java serialization and Hessian serialization
In the remote call, the parameters and return values need to be transmitted through the network. This use requires serialization to convert the object into a byte stream, and then deserialization from one end to the other to become an object.
Since the previous article mentioned Hessian, let's briefly talk about the difference between Java serialization and Hessian serialization.
First, Hessian serialization is much more efficient than Java serialization, and the generated byte stream is much shorter. However, it is not as reliable as Java serialization, and it is not as comprehensive as Java serialization support. The reason for this difference is from their implementation.
Let's talk about Java serialization first. The specific working principle will not be mentioned. Java serialization will serialize all the metadata and business data of the object class to be serialized from the byte stream, and serialize all the things in the whole inheritance relationship. The serialized byte stream is a complete description of the structure and content of the object, and contains all the information. Therefore, the efficiency is low and the byte stream is relatively large. However, because all content is serialized, it can be said that everything can be transmitted, so it is more usable and reliable.
The implementation mechanism of Hessian serialization is to focus on data with simple type information. Like integer a = 1, Hessian will be serialized into a stream such as I 1. I means int or integer, and 1 is the data content. For complex objects, Hessian serializes all the attributes of the object as a map through Java's reflection mechanism, Generate similar m classname propertyname1 I 1 propertyname s stringvalue (about so, forget exactly) such a stream contains the basic type description and data content. In the serialization process, if an object has appeared before, Hessian will directly insert a block such as R index to represent a reference location, so as to save the time of reordering and deserialization. The cost of this is that Hessian needs to identify different types Different processing is performed (therefore, Hessian is lazy directly and does not support short), and special processing is required for some special objects (such as stacktraceelement). At the same time, because it does not go deep into the implementation for serialization, certain inconsistencies will occur in some cases, such as the map obtained through collections.synchronizedmap.
summary
The above is all about the differences between Java serialization and Hessian serialization. I hope it will be helpful to you.