Java Serialization Technology

Source: Internet
Author: User

Java serialization is the conversion of an object into a string of binary representations of byte arrays, which are persisted by saving or transferring the byte data. To persist, the object must implement the Java.io.Serializable interface. Deserialization is the opposite process of re-structuring the byte array into an object. When deserializing, it is necessary to have the original class as a template in order to restore this object, from which we can guess that the serialized data does not hold the complete structure information of the class like the class file. So what exactly does the serialized data contain?

Although the serialization of Java can guarantee the persistence of object state, it is difficult to deal with some complex object structures, the following is a summary of some complex object situations:

    1. When the parent class implements the Serializable interface, all subclasses can be serialized
    2. Subclasses implement the Serializable interface, the parent class does not, the attributes in the parent class cannot be serialized (without error, but the data is lost), but the attributes are still serialized correctly in the subclass.
    3. If the serialized property is an object, the object must also implement the Serialiazable interface, otherwise it will error.
    4. When deserializing, if the properties of an object are modified or truncated, the modified part of the property is lost but does not cause an error.
    5. When deserializing, if Serialversionuid is modified, the deserialization fails.
Java serialization works well in a pure Java environment, but in a multi-lingual environment, it is difficult to restore results in other languages after the storage is serialized in Java. In this case, as far as possible to store common data structures, such as JSON or XML structure data, there are better serialization tools, such as Google's protobuf.

Java Serialization Technology

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.