The reason I ask this is because I am currently getting this error
java.io.InvalidClassException: com.my.package.TestObject; local class incompatible: stream classdesc serialVersionUID = 8401131515464509133, local class serialVersionUID = 581907934314849590
I get this because I am reading an old version of an object from a Redis cache but I have changed the object to have a new field - the old version of the class did not originally have a serialVersionUID so it's using this auto-generated one.
e.g old version
public static class TestObject implements Serializable {
String id;
String name;
}
new version
public static class TestObject implements Serializable {
String id;
String name;
String newField;
}
Q - So my question is if I add private static final long serialVersionUID = 8401131515464509133L
to the class will it be a problem for other instances of the object?
EDIT: the main question I am asking is does the value that was computed for the auto-generated serialVersionUuid each time a class is compiled? or can I rely on it been the same every compile? (when no new fields are added)?