• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Serializing more than one value manually

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic