Solved

Java object Serializable new Properties

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
A short article about problems I had with the new location API and permissions in Marshmallow
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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 …

757 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

18 Experts available now in Live!

Get 1:1 Help Now