Java object Serializable new Properties

Is there any way to add properties to a class that is saved using:

ObjectOutputStream oos = new ObjectOutputStream(.....));
oos.writeObject(myObject);

I have a number of objects already saved and would like a way to retrieve them into the new version of my object that has additional properties (obviously these will be null until the new version is saved)
Thanks
va3jslAsked:
Who is Participating?
 
nareshvootaCommented:
You have to provide serialVersionUID field manually and ensure it is always the same no matter what changes are made to the file.

http://java.sun.com/developer/technicalArticles/Programming/serialization/

Look for a detailed description of version control in the above article.

Hope this helps.
0
 
Sharon SethCommented:
If the serialVersionUID differs (which means the class version has changed) , you will get a incompatible class error while trying to deserialize
0
 
nareshvootaCommented:
Yes

private static final long serialVersionUID = 12121212L;

put this in the class and the serial version remains same even if you add new fields.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.