java serialization and deserialization

Introduction to the concept of object serialization and deserialization

      Serialization: The process of converting an object into a byte array is called object serialization.

     Deserialization : The process of restoring a byte array to an object is called object deserialization.


Two uses of serialization

1. Permanently save the byte sequence of the object to the hard disk

      2. Transmit the byte sequence of the object on the network - the default serialization is not safe, you can customize the serialization

     Objects that need to be serialized need to implement the java.io.Serializable interface ( there is no method, it is an identity interface ) .

Fields that the class does not participate in serialization

     1. Static variables (static modification)

 2. Transient modified variables

 Fields that do not participate in serialization will be set to the default value of the type in the deserialized instance .


Java.io.Externalizable 与 java.io.Serializable

  java.io.Externalizable is a sub-interface of java.io.Serializable, which is more flexible to use and can control which fields are serialized and which fields are deserialized

The role of serialVersionUID serial number

Answer: For a class that implements the serialization interface , jvm compares the serialVersionUID in the byte stream with the serialVersionUID of the local entity class when deserializing . If they are the same, they can be deserialized, otherwise an exception will be thrown.

Guess you like

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