Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deserialization

 
abhinas raj
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does Deserialization depeneds on .class file or not or it only depends on serialversionUID ?
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the API docs for Serializable(emphasis mine)
The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization

Check out the API docs for more info. They are quite descriptive
 
Campbell Ritchie
Sheriff
Posts: 48440
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abhinas raj,
Your post was moved to a new topic.
 
david foley
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


deserialization depends on a number of factors is your Class implementing serialization and that your serialization ID numbers match up with one another

 
abhinas raj
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i changed the class name (keeping variable name's same), and serialversionUID same as privious, when i deserialized the objects, i got the desired result, i mean practically it was working. so if class name is different then also object is serialized (by keeping the serialversionUID same as previous), then how can we say that deserialization depends on .class file also.
 
abhinas raj
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:From the API docs for Serializable(emphasis mine)
The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization

Check out the API docs for more info. They are quite descriptive




where can i find the API docs ? thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you ShowSomeEffort and google "Serializable" you will find what you seek.
 
abhinas raj
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks all
 
david foley
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say .class what class are we talking about your setters and getters? Or you main class?

If you do not implement serialisation inside the .class with your setters and getters your objects will not be saved to file

If you do not overwrite the String tostring() method it will not be displayed readable when you do your deserialization.



 
abhinas raj
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
david foley wrote:When you say .class what class are we talking about your setters and getters? Or you main class?

If you do not implement serialisation inside the .class with your setters and getters your objects will not be saved to file

If you do not overwrite the String tostring() method it will not be displayed readable when you do your deserialization.



1) i am talking about the class that has implemented the Serializable interface. and that will be used at the time of deserialization.
2) the class that implemented Serializable, i have not written setter,getter. i have used constructor.
3) yaa toString() method must be overriden

i have studied the API docs. and some other stuffs also. still i am not able to decide that Deserialization depends on the .class file (the class file which has implemented the Serializable interface). because if i am using serialVersionUID inside the class, then if i change the name of the class and used the .class file of this changed class to deserialize the object, then it is deserialized easily. then .................................... how can i say that deserialization depends on the .class file.
 
david foley
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



i have studied the API docs. and some other stuffs also. still i am not able to decide that Deserialization depends on the .class file (the class file which has implemented the Serializable interface). because if i am using serialVersionUID inside the class, then if i change the name of the class and used the .class file of this changed class to deserialize the object, then it is deserialized easily. then .................................... how can i say that deserialization depends on the .class file.

Since your only Changing the Name of the Java Class. it will not effect any Methods in the class,

Change a few Methods inside that class and try deserialization i have a idea that it will give you a Runtime Error.
 
abhinas raj
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry when i changed the name of .class file then it show giving java.lang.ClassNotFoundException , but when i kept .class file name same as previous and changed the method name inside that class then it was not giving any error. in the file where the serialized object is stored the class name is also present, so how if i change the name of .class file then the object will be deserialized ?
 
Paul Clapham
Sheriff
Pie
Posts: 20764
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this point I really have no idea what your questions are all about.

So far you've found out that you can't deserialize data for a class which isn't in your classpath. But that doesn't have anything to do with the serialVersionUID value. Was that question the one you meant to ask? Or was there some other question?
 
Henry Wong
author
Marshal
Pie
Posts: 20902
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I actually don't understand the original question...

abhinas raj wrote:does Deserialization depeneds on .class file or not or it only depends on serialversionUID ?


The serialization version id is either calculated from the class, or actually a static variable of the class -- so how can anything be dependent on the serialization version id, but not dependent on the class where the id has been calculated or gotten from?

Henry
 
abhinas raj
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:I actually don't understand the original question...

abhinas raj wrote:does Deserialization depeneds on .class file or not or it only depends on serialversionUID ?


The serialization version id is either calculated from the class, or actually a static variable of the class -- so how can anything be dependent on the serialization version id, but not dependent on the class where the id has been calculated or gotten from?

Henry


there was a warm discussion between me and some of my friends about deserialization. they were telling like deserialization never depends on the .class file (the class which has implemented the Serializable interface, and which is used to deserialize the serialized object). according to them deserialization depends only on the serialVersionUID. and i had a bit of confusion about that. ..................... thanks for your valuable reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic