Solved

Help with Serialization

Posted on 2007-11-23
6
207 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
windows explorer path to command prompt 5 54
Oracle SQL syntax check  without executing 6 75
maven module vs maven project 3 47
web project error add remove 1 32
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

828 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