• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Problem with read-write methods in Serialization

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
During serialization, if I'm implementing my own writeObject & readObject methods then which method should I use to read a String.

Please view the following code:



Here I've written a String using writeChars() methods while serializaing object. But there is no similar method while reading object during de-serialization.

Can anyone help me out in same.

NOTE - I know that we can do same using defaultWriteObject()/defaultReadObject() methods. But I intentionaly want to go this way. Please provide a solution in the same context.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lalit,

Even I checked the ObjectInputStream API and could not find any related method for reading a String. But can't we use public final Object readObject() method, as String extends Object. I haven't tried this, but just a thought.
 
Lalit Bansal
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chandra,

It works with writeObject() and readObject() methods.

Thanks.

regards,
 
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic