1. What is serialization?
Serialization is simply serializing an object into a byte stream for network transmission or persistence.
2. Serialized usage scenarios?
A). Persist objects in memory to a file or database;
b). The object is transmitted over the network.
3. Serialization implementation?
1). Implement the Serializable interface:
This method is simple and does not have any methods that need to be implemented.
The author (web development) has been using this method for two years, this method is mainly explained below.
2). Implementing the Externalizable Interface: Externalizable is the sub-interface of serializable
This method requires the implementation of a method that can control the properties of the serialization itself.
4. Serializable use notes for serialization
1. The serialization ID must be consistent.
There are three conditions for the virtual machine to allow deserialization: the class path is consistent, the function code is consistent, and the serialization ID of the two classes is identical;
2. The Reference object B,a in Object A is serialized, and b is also serialized;
3. When the parent object is serialized, the child object is also serialized
4. When the subclass object is serialized, the parent object is not serialized, and the default parameterless constructor is called to construct the object when deserializing;
5. When there is a transient modifier in the serialized object before the attribute, the property is not serialized because the transient property is temporary;
6. When there is a static modifier in the serialized object before the property, the property is not serialized, because static represents a secondary attribute that is a class property that is not an object property;
7. There are attributes in the serialized object that are sensitive fields and need to be encrypted for transmission, you need to customize serialization and deserialization. It is important to note that even if the object's properties are private, it is not safe to handle the security manually.
Custom methods: Customize the WriteObject () and ReadObject () methods in the serialized class, and the virtual opportunity to invoke the WriteObject and ReadObject methods in the object class for user-defined serialization and deserialization,
If there is no such method, the default call is the Defaultwriteobject method of ObjectOutputStream and the Defaultreadobject method of ObjectInputStream.
6. Serialization of storage rules: When writing a file to the same object, and no longer store the contents of the object, but just another copy of the reference, the file size does not double, only slightly increased (added control information).
Java Serialization Knowledge Collation