File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Object deserialiaztion .... with different versionUid Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Object deserialiaztion .... with different versionUid" Watch "Object deserialiaztion .... with different versionUid" New topic
Author

Object deserialiaztion .... with different versionUid

Debopam Poddar
Ranch Hand

Joined: Jun 21, 2005
Posts: 49

I have a class PersonDetails with version 1

public class PersonDetails implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;

private String name;
private int age;

//getter,setter methods
}


With this version I have serialized one PersonDetails object into a file. Now I have added one more field and updated the versionUid to 2



public class PersonDetails implements Serializable {

/**
*
*/
private static final long serialVersionUID = 2L;

private String name;
private int age;
private String address;

//getter,setter methods
}


Now if I want to deserialize the object it thows me
. If I do not update the versionUid to 2 it deserialize the object successfully and put Address as null.

My question is there any way to deserialize the object keeping the updated versionId?
Abhi Deshmukh
Greenhorn

Joined: May 05, 2010
Posts: 7
I think we can not deserialize the object keeping the updated serialVersionUID.
It is because serialVersionUID is an exception to the rule that “static fields don’t get serialized”.
ObjectOutputStream writes every time the value of serialVersionUID to the output stream.
ObjectInputStream reads it back and if the value read from the stream does not agree with the serialVersionUID value in the current version of the class, then it throws the InvalidClassException.

SCJP 5.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object deserialiaztion .... with different versionUid