File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serialization doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Serialization doubt" Watch "Serialization doubt" New topic
Author

Serialization doubt

Ami Ambre
Ranch Hand

Joined: Dec 26, 2007
Posts: 58
When you want to do only a part of the serialisation/deserialisation
yourself you must invoke the defaultReadObject() & defaultWriteObject().

What defaultReadObject() & defaultWriteObject() does?
kunal dabir
Greenhorn

Joined: Sep 08, 2008
Posts: 15
When you want to do only a part of the serialisation/deserialisation
yourself you must invoke the defaultReadObject() & defaultWriteObject().

What defaultReadObject() & defaultWriteObject() does?


1. It's not compulsory to invoke defaultReadObject() & defaultWriteObject().
2. both methods are called to carry out the serialization/deserialization process which would occur if you had not implemented read/writeObject.

Also remember, the order in which you call defaultXXXObject() inside XXXObject() is also very important.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

defaultReadObject and defaultWriteObject methods read and write non-static fields of a class which are not transient...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
Where I have seen that discussed is in the case where you want to write out field values that are non-serializable so you override the writeObject() and readObject() methods. Within your overridden method you still have to account for serializing the serializable part of the object/object graph, so you should imbed a defaultWriteObject() / defaultReadObject() to do the normal part of serialization/deserialization. At least that is what I thought it was.


------------------------
Bob
SCJP - 86% - June 11, 2009
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serialization doubt
 
Similar Threads
Serialization
Serialization in java
defaultReadObject() required?
Serialization
Regarding Serialization!!