I have got a problem with Java serialization. Suppose I had one Object persisted to file system. How can we update the structure of the files according to object structure modification in latter version?
For example if I saved Object
A{int a; String b} to file
And I changed a structure to A{int a; String b, char c} is there any way I can change previous saved files according to latter version of A?
It’s possible. You’ll need to make the next version backward-compatible with the previous version. The ways to do that are explained in the Java serialization specification: http://docs.oracle.com/javase/1.3/docs/guide/serialization/spec/version.doc.html.
This problem, however, is a good example of why using the native Java serialization to persist objects for a long time is usually a bad idea. If you had used a specific format (XML, JSON or whatever), you could easily read and transform the files themselves, or be able to read any version of the file with different implementation of the serializer, and thus migrate more easily from one version to another.