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 Serialization 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 "Serialization " Watch "Serialization " New topic
Author

Serialization

peria samy
Greenhorn

Joined: Jun 17, 2013
Posts: 6
Here i tried to serialize Dog object that has another object Coller which is not serializable one so that i marked it as transient. but i wanted to serialize only one variable (size)of Coller object. i don't know how to print value of object that is deserialized. i tried but it shows error.



Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
it shows error.

Which is?


Ping & DNS - updated with new look and Ping home screen widget
peria samy
Greenhorn

Joined: Jun 17, 2013
Posts: 6
Normally readObject() method is used to deserialize object. but i used defaultReadObject() method to deserialize object.Here is problem to me because i don't know to print the value of an object that is deserialized. I tried using this syntax(Dog d=(Dog)os.defaultReadObject()) Here error occurs.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18118
    
  39

peria samy wrote:Normally readObject() method is used to deserialize object. but i used defaultReadObject() method to deserialize object.Here is problem to me because i don't know to print the value of an object that is deserialized. I tried using this syntax(Dog d=(Dog)os.defaultReadObject()) Here error occurs.



First, can you properly format your code? Your code, as currently written is very difficult to read. Second, while most of us know the source, can you still QuoteYourSources? Thanks.


Anyway, the purpose of defaultReadObject() is to deserialize the object. You can use the object (ie. for printing the values) after you deserialize it. There is no need to have one line that both deserialize and print the object.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
peria samy
Greenhorn

Joined: Jun 17, 2013
Posts: 6
Thank you Henry Wong. i will follow your instruction hereafter. i got the point.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1945
    
  28
peria samy wrote:I tried using this syntax(Dog d=(Dog)os.defaultReadObject()) Here error occurs.

You can only deserialize that which you have serialized and you haven't serialized a Dog object.
peria samy
Greenhorn

Joined: Jun 17, 2013
Posts: 6
Tony Docherty wrote:
peria samy wrote:I tried using this syntax(Dog d=(Dog)os.defaultReadObject()) Here error occurs.

You can only deserialize that which you have serialized and you haven't serialized a Dog object.

Hai Tony Docherty actually i stated that "i used this syntax(Dog d=(Dog)os.defaultReadObect())". but my source code does't have that. i want to explian my problem with example that is why i mentioned like that
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serialization
 
Similar Threads
Doubts in Serialization
ObjectInputStream question
Serialization
How it works when we implement writeObject and readObject
Serialization in java