Link to home
Start Free TrialLog in
Avatar of sukh54
sukh54

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sukh54
sukh54

ASKER

But , how we can check the checksum in the runtime ....and also is it flexible .. Will appreciate if you place some code snippet ...
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.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sukh54

ASKER

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial