aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problem with read-write methods in Serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Problem with read-write methods in Serialization" Watch "Problem with read-write methods in Serialization" New topic
Author

Problem with read-write methods in Serialization

Lalit Bansal
Ranch Hand

Joined: Jan 29, 2007
Posts: 63
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.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jan 29, 2007
Posts: 63
Hi Chandra,

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

Thanks.

regards,
 
Don't get me started about those stupid light bulbs.
 
subject: Problem with read-write methods in Serialization