I need an advice about compatible changes and serialVersionUID (http://docs.oracle.com/javase/6/docs/platform/serialization/spec/version.html#6678).
I work on a system with a 'client' project which communicates with 'server' project using RPC ('server' exports data from DB using DTO classes and 'client' presents that data using the same DTO classes).
When a field is added in a DTO class, the team decided not to change serialversionUID, so when a new version of 'server' is deployed, 'client' doesn't need to be deployed immediately, because older version of that DTO class is compatible with a new one.
But (as we have a few dozen of system instances with both projects), if a new version of 'client' is deployed with new version of DTO class, and 'server' for some reason remains at the old version, then the new field of DTO class will resolve to null, and will be presented as null to customer, which may be incorrect.
Is there any kind of best practice to address this issue? We can change the UID on any kind of changes in DTO classes, but then we'll always have to deploy both projects at the same time, even when changes are not used, and we are trying to avoid that...
Changing the UID is not the solution, it is part of the problem. Don't do that.
When you add the new field, you can also add logic into the readObject()
method of the same class to give it a sensible default value if it's null.