serialization - java.io.InvalidClassException while deserializing object after some modification in a java class -


why failed deserialized have serialized container class using serialversionuid = 75264711556228l;

public class container implements serializable {     private static final long serialversionuid = 75264711556228l;     public boolean isfromlocalcollect=false;     public boolean isfromlocalcollect=false;     public void setfromlocalcollect(boolean isfromlocalcollect) {         this.isfromlocalcollect=isfromlocalcollect;     }     public boolean getfromlocalcollect() {         return this.isfromlocalcollect;     } } 

now have added 1 more setter , getter method in container class after serialized name container.ser like:

public class container implements serializable {     private static final long serialversionuid = 75264711556228l;     public boolean isfromlocalcollect=false;     public boolean isfromlocalcollect=false;     public void setfromlocalcollect(boolean isfromlocalcollect) {         this.isfromlocalcollect=isfromlocalcollect;     }     public boolean getfromlocalcollect() {         return this.isfromlocalcollect;     }     public boolean isfromlocalcollect2=false;     public void setfromlocalcollect2(boolean isfromlocalcollect2) {         this.isfromlocalcollect2=isfromlocalcollect2;     }     public boolean getfromlocalcollect2() {         return this.isfromlocalcollect2;     } } 

then trying deserialize object using project name changed failed deserialized , error got like:

java.io.invalidclassexception: cvb.db.pbdb; local class incompatible: stream classdesc serialversionuid = -444070985558173412, local class serialversionuid = 4350771162641935418 

when serialized object used version of container.class differents container.class used deserialize it.

you need use same .class sure operation of serialization deserialization work correctly.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -