Solved

Java object Serializable new Properties

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

805 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