Solved

serialVersionUID update

Posted on 2009-07-06
7
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 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 250 total points
ID: 24792817
You choose the UID - it's not a problem.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 238
eclipse buid path vs tomcat lib path 10 38
Desingning Refactoring existing code 2 31
How to determine if a string is a valid SHA value 7 43
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

756 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