This socket will keep receiving some old objects and new objects with same name. However, if I used readObject directly, it will throws fatal exception. Some of us would suggest to ignore old object or change the old object code. This is not possible for me to change client codes. I need to handle the backward-compatibility.
Socket s = ss.accept();
ObjectInputStream lvStream = new ObjectInputStream(s.getInputStream());
Object lvObject = lvStream.readObject();
// The old class but released ( I cannot change it )
public class Apple extends HashMap<String, String> {
private static final long serialVersionUID = 1L;
}
// The old class but released ( I cannot change it )
public class Apple extends HashMap<String, String> {
private static final long serialVersionUID = 2L;
}
// The new class in my local ( 1L or 2L still would not solve the issue easily )
public class Apple extends HashMap<String, String> {
private static final long serialVersionUID = 2L;
}
At the line of readObject(), I got this fatal exception:
java.io.InvalidClassException local class incompatible : stream classdesc serialVersionUID = 1, local class serialVersionUID = 2
How could I read this two kind of Apple objects data (the Hashmap)?
Thank You.