views:

225

answers:

3

I have compiled and jarred the various projects in my Java application, generating serialVersionUIDs automatically through Eclipse for all my classes derived from Serializable.

I read the answers to this question, and verified that serialVersionUids are all private static final long.

Nevertheless, I get an error like this when I try to run:

java.io.InvalidClassException: com.acme.product.Widget; local class incompatible: stream classdesc serialVersionUID = 5226096973188250357, local class serialVersionUID = -5432967318654384362

What am I missing?

+1  A: 

You probably have a classpath issue, where your program is resolving an older incompatible version of the class which has a different value for serialVersionUID.

Or the serialized object that is being loaded, was serialized with an oder version of the class which is now unavailable.

crowne
+1  A: 

If the class has changed since you serialized it, the change may be incompatible. Serialization can't deserialize it, even with the included serialVersionUID.

If you have the class as it was when serialized (e.g. from SCM), then try reverting back to that, regenerate the serialVersionUID and rerun.

If you have made incompatible changes, then you will have to implement readObject() /writeObject() to handle the serialization details yourself.

mdma
A: 

stream classdesc serialVersionUID = 5226096973188250357

What am I missing?

What you are missing is private static final long serialVersionUID = 5226096973188250357L;

However if the changed class is no longer serialization-compatible (see the Object Serialization Specification) you may now get more obscure errors.

EJP
Why the downvote?
EJP