Solved

Java object Serializable new Properties

Posted on 2012-03-14
3
415 Views
Last Modified: 2012-03-15
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
0
Comment
Question by:va3jsl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
nareshvoota earned 400 total points
ID: 37723164
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
 
LVL 12

Assisted Solution

by:Sharon Seth
Sharon Seth earned 100 total points
ID: 37723608
If the serialVersionUID differs (which means the class version has changed) , you will get a incompatible class error while trying to deserialize
0
 
LVL 1

Assisted Solution

by:nareshvoota
nareshvoota earned 400 total points
ID: 37724212
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question