File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Serialization Failing with Incompatiable class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Serialization Failing with Incompatiable class" Watch "Serialization Failing with Incompatiable class" New topic
Author

Serialization Failing with Incompatiable class

Karthikeyan Srinivasan
Greenhorn

Joined: Jan 31, 2008
Posts: 3
Hi Friends,

I have an class which implements serializable.i have made some changes and redeployed but its giving me the InvalidClassException.incompatiable Classes and diffrent serialversioUID in the stream class and local class.
I have added the serialversionUID in the log which shown and its working fine.


But..is the same serialVersionUID would works for all envn.because i have tried in my QA and Dev envn..but when it goes to prodn is it works?

what if instead hard coding the serialversionUID to some value shown in the Log... by 1L?

my Sub Class extends the Class which Base Class is Serializable actually,is the need of my subclass holds this value..i founded my base class does nt have the serialversionUID.?

Please help on this.

Thanks,
karthik.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Welcome,

http://faq.javaranch.com/java/TellTheDetails
http://faq.javaranch.com/java/UseRealWords

Show us the code. Copy/paste the actual errors. Then we can help much more easily without us having to guess what's going wrong.


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Karthikeyan Srinivasan
Greenhorn

Joined: Jan 31, 2008
Posts: 3
Thanks everybody who looks..its worked just added by the serialVersionUID in the subclass.and ofcourse i will take care of to post the topic with correct example...
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
If a class is Serializable, but there is no serialVersionUID field, then Java makes up its own UID for the class. This changes if the fields or methods change. So a tiny change to the class can result in serialisation failure.

If you give a serialVersionUID field in the class, and it is the same as one being read from a stream, Java will attempt to populate the object with the values from the stream. Any fields present in the stream, and missing in the class, will be ignored. Any fields present in the class, and missing in the stream, will be defaulted (normal Java rules apply).

Normally, the actual value of serialVersionUID does not matter all that much. You could use 1 for all classes. However, that would pretty much defeat all the checking, so might not be advisable.

One approach is to find out the UID of the first version of your class, when it doesn't have a serialVersionUID field, set serialVersionUID to that value, and leave it at that value forever. Or, at least, until you make changes that mean that old serialised streams really can't be read.

Another approach (what I usually do) is just to make up a random number in my head, when I first write the class.

If you have to read streams that were written before you added a serialVersionUID field, you should set your serialVersionUID to the value in the stream (assuming there's just one value, else you're stuck).


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Serialization Failing with Incompatiable class
 
Similar Threads
problem in tracing code?!
Deserializing an object using a class description which does not contain a field in the object.
Serialization - different JVM version ?
ArrayList problem ...
Problem Persisting Entity In Hibernate