当前位置:网站首页>The IDEA to automatically generate the serialVersionUID

The IDEA to automatically generate the serialVersionUID

2022-08-10 03:32:00 struggling newbie

Serialization and Deserialization

Java is an object-oriented language. To interact with other languages ​​(such as HTTP communication with front-end js), it is necessary to convert objects into a common format such as json (the front-end obviously does not recognize Java objects), from objects to json charactersThe conversion of strings is the process of serialization, and conversely, the conversion from json strings to Java objects is the process of deserialization.

What is serialVersionUID

The deserialization process requires generating a Java object from a json string.
There will be a problem at this time. It is necessary to verify whether the input json string is serialized from the current Request class. SerialVersionUID is used for this.When the serialVersionUID during serialization is inconsistent with the serialVersionUID during deserialization, an InvalidCalssException will be thrown.
The specific serialization process is as follows: During the serialization operation, the system will write the serialVersionUID of the current class into the serialized file. When deserializing, the system will detect the serialVersionUID in the file to determine whether it matches the serialization.The serialVersionUID of the current class is consistent. If it is consistent, it means that the version of the serialized class is the same as the current class version, and the deserialization can be successful, otherwise it will fail.

How to generate

First we will implement the interface, so how to automatically generate serialVersionUID.

Set the way to automatically generate serialVersionUID as shown below
Insert image description here
After checking as shown in the picture, select the class name, and then press alt+enter to display the options shown below
insert image description here
Once selected, it will generate
Insert image description here

原网站

版权声明
本文为[struggling newbie]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208100204278115.html