• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serialization

 
peria samy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it shows error.

Which is?
 
peria samy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21003
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
peria samy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Henry Wong. i will follow your instruction hereafter. i got the point.
 
Tony Docherty
Bartender
Posts: 2953
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic