Solved

Help with Serialization

Posted on 2007-11-23
6
181 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
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
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
Comment Utility
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
Comment Utility
manage your serialVersionUID as pellep has mentioned above
http://www.javapractices.com/Topic45.cjp

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.

771 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

12 Experts available now in Live!

Get 1:1 Help Now