• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Serialization Failing with Incompatiable class

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Karthikeyan Srinivasan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
The only cure for that is hours of television radiation. And this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic