Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

serialVersionUID update

Posted on 2009-07-06
7
Medium Priority
?
263 Views
Last Modified: 2012-05-07
For serialized objects , if the serialVersionUID is not defined explicitly, by compile time java compiler creates a new one and this is compiler dependent.

We need to enforce that , if the update of object is incompatible with the new object, serialVersionUID must be set to a new value, otherwise it should remain unchanged. i.e If any attribute is deleted from the object serialVersionUID must be updated.

I am thinking to use externalize mechanism to serve the purpose . This is time consuming . But , is there any other way that makes the job easy and faster.
0
Comment
Question by:sukh54
  • 3
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 1000 total points
ID: 24792199
You could use the checksum of the classfile as its serialVersionUID and check that they correspond
0
 

Author Comment

by:sukh54
ID: 24792285
But , how we can check the checksum in the runtime ....and also is it flexible .. Will appreciate if you place some code snippet ...
0
 
LVL 6

Expert Comment

by:jwenting
ID: 24792424
A good way would be to use an ANT (for example) task that generates the serialVersionUID according to some algorithm and injects the definition into the source.
Of course you'd have to work always on a copy of the source, and store in your version control system a version that only has a placeholder telling the task where to inject the actual value.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 1000 total points
ID: 24792452
0
 

Author Comment

by:sukh54
ID: 24792775
But , how about explicitly specifying the serialVersionUID in the serializable
classes?  .... the most worrying part is , I am wondering will it give any issue (InvalidClassExceptions) since the class defintions( with the added new filed serialVersionUID) may not match the corresponding serailized objects( which didnt have the field serialVersionUID) ...
         If the issue are there , how we can go about this
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 1000 total points
ID: 24792817
You choose the UID - it's not a problem.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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 …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

772 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