aspose file tools*
The moose likes Beginning Java and the fly likes Deserialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Deserialization" Watch "Deserialization" New topic
Author

Deserialization

abhinas raj
Ranch Hand

Joined: Jun 02, 2012
Posts: 47
does Deserialization depeneds on .class file or not or it only depends on serialversionUID ?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10245
    
    8

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


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38334
    
  23
abhinas raj,
Your post was moved to a new topic.
david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 58


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

Joined: Jun 02, 2012
Posts: 47
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

Joined: Jun 02, 2012
Posts: 47
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

Joined: Jan 10, 2002
Posts: 60975
    
  65

If you ShowSomeEffort and google "Serializable" you will find what you seek.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
abhinas raj
Ranch Hand

Joined: Jun 02, 2012
Posts: 47
thanks all
david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 58
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

Joined: Jun 02, 2012
Posts: 47
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

Joined: Dec 01, 2012
Posts: 58



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

Joined: Jun 02, 2012
Posts: 47
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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
Sheriff

Joined: Sep 28, 2004
Posts: 18702
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
abhinas raj
Ranch Hand

Joined: Jun 02, 2012
Posts: 47
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
 
Consider Paul's rocket mass heater.
 
subject: Deserialization