[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

serialVersionUID update

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
sukh54
Asked:
sukh54
  • 3
  • 2
3 Solutions
 
CEHJCommented:
You could use the checksum of the classfile as its serialVersionUID and check that they correspond
0
 
sukh54Author Commented:
But , how we can check the checksum in the runtime ....and also is it flexible .. Will appreciate if you place some code snippet ...
0
 
jwentingCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
CEHJCommented:
0
 
sukh54Author Commented:
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
 
CEHJCommented:
You choose the UID - it's not a problem.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now