Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serialization doubt

 
Ami Ambre
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
defaultReadObject and defaultWriteObject methods read and write non-static fields of a class which are not transient...
 
Bob Ruth
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic