I have a serializable class.
public class Customer implements Externalizable {
private static final long serialVersionUID = 1L;
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName( String name) {
this.name = name;
}
@Override
public String toString() {
return "id : "+id+" name : "+name ;
}
@Override
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
this.setId((String) in.readObject());
this.setName((String) in.readObject());
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
System.out.println("Reached here");
out.writeObject(id);
out.writeObject(name);
}
}
I have serialized the object of the class into a file. Now I have changed the datatype of name from String to List. So while deserializing, I am getting a class cast exception because it is not able to convert from String to List. I was thinking of changing the version of the class every time some change is made to the class so that in the readExternal I can handle it explicitly. However while this idea might be able to work for simple classes it would fail in case of larger complicated classes. Can anyone please provide a simpler solution to this.
Thanks