Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serializing more than one value manually

 
Catherine Zhu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My question is, how do you serialize more than one int that cannot be serialized automatically. i.e. two transient int variables. And how do you tell them apart when you deserialize the object?

Next question is... do we need to know this for the exam? Well actually I would like to know anyway.

Thanks.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Cat,"

Please check your private messages by clicking on the "My Profile" link near the top of the page. Thanks!
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy ranchers,

and thank you, Cat, for changing your display name.

Welcome to the ranch!



To your question:
You have to write the two ints seperately. And read it seperately.
When you make the private void writeObject(ObjectOutputStream os) - method and the complementary readObject method, you have to be sure to do this in the right sequence.

Here is an example where I mixed it up (bold):

output:
[Bird with 2 legs and 2 wings, Fly with 6 legs and 2 wings]
null
[Bird with 2 legs and 2 wings, Fly with 2 legs and 6 wings]




Hope that helped.

Yours,
Bu.
 
Catherine Zhu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic