Solved

serialVersionUID update

Posted on 2009-07-06
7
244 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
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
Comment Utility
You could use the checksum of the classfile as its serialVersionUID and check that they correspond
0
 

Author Comment

by:sukh54
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
Comment Utility
0
 

Author Comment

by:sukh54
Comment Utility
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 250 total points
Comment Utility
You choose the UID - it's not a problem.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 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

7 Experts available now in Live!

Get 1:1 Help Now