Solved

Java object Serializable new Properties

Posted on 2012-03-14
3
406 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now