Common scenario in web applications:
- the application has many classes that need to be stored in the session and are serializable
- developer receives a bunch of warnings about "Serializable class does not implement serialVersionUID"
- the developer shrugs and clicks on the IDE "add serialversionUID", and the problem is solved?
I donโt like automatically adding serialVersionUID in principle, since the solution essentially means that
- the most important states of developers: "I know when my changes interrupt serialization, and when not, and want to control it instead of the JVM," when in fact he doesnโt know these things and doesnโt want to control them
- adding serialVersionUID = 6266256561409620894L is confusing and ugly (ok, you can use 1L)
I understand that adding serialVersionUID to an application where class compatibility is a problem, and developers actively take this into account and understand the problems associated with it.
In a typical web application, this is not very important when the serialization of classes breaks or not. When a new version is deployed, some extraneous serialized sessions may be corrupted, but this is usually not a problem (and several applications actually handle compatibility with serial versions of sessios).
Bottom line: isn't the tip โAlways define serialVersionUID explicitly in your source filesโ simplistic?
source share