Solved

Help with Serialization

Posted on 2007-11-23
6
193 Views
Last Modified: 2010-03-30
Hi,

I am using Serialization to develop an application.  I am aware that if you change the application, there are issues with it.

How does one overcome this in the development phase.   I.e. As I am currently developing the application it is being changed. For example - the first part of the application that I am developing is for loading and saving the pick lists.  This will be used for all other components of the applications.  So if I create all the pick lists I worry that I will have to recreate them all again as I will not be able to load it.

Any help tips?
0
Comment
Question by:amacfarl
6 Comments
 
LVL 26

Expert Comment

by:ksivananth
ID: 20338848
if the class is not modified, you won't have any issue. If you expect the class to be modified in future why don't you extract and store the data in XML?
0
 
LVL 2

Author Comment

by:amacfarl
ID: 20339001
what happens if the attributes are not modified but the methods are?
what happens if the class is not modified, but sub classes are?
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 20339025
>>what happens if the attributes are not modified but the methods are?

I think, there will be issues...

>>what happens if the class is not modified, but sub classes are?

No issues, as long as you ser and deser into same class.

0
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.

 
LVL 86

Expert Comment

by:CEHJ
ID: 20339026
You should use a build tool such as Ant to automate the building and deploying ot the app so you can keep careful control of the binaries
0
 
LVL 4

Accepted Solution

by:
pellep earned 500 total points
ID: 20339143
Serialization compatability at runtime is determined by the serialVersionUid. It's a field in the class that, if you don't declare it explicitly, gets generated by the compiler for you if you implement Serializable. The significance of the field is central. If you attempt to deserialize an instance of a class and the serialVersionUids doesn't match on the deserialized form and the class definition, you will get an InvalidClassException thrown at you.

Different compilers have different strategies regarding the computation of this field. Some may modify it any time you change the class, some are smarter and will only modify it if you make changes that affect serialization, like changing the name or type of a field in the class.

To control this yourself, declare the servialVersionUid explicitly in the class you are serializing, like

private static final long serialVersionUID = 7526472295622776147L;

Don't modify it unless you are releasing a new version of the class that you know won't be able to deserialize and older version (for instance changing names or types of fields). Take care when you override this though, since you're essentially telling the JRE that "don't worry about version compatability, I know what I'm doing".
0
 
LVL 92

Expert Comment

by:objects
ID: 20340827
manage your serialVersionUID as pellep has mentioned above
http://www.javapractices.com/Topic45.cjp

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

Suggested Solutions

Title # Comments Views Activity
Impossible to extract MSI from new JAVA releases 2 50
Securing Jmx Console and web console 2 66
Java Server Faces parameter pass? 6 39
simple java question 3 44
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

863 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

20 Experts available now in Live!

Get 1:1 Help Now