• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Serialization

 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am little confuse about private methods writeObject() & readObject(), also defaultWriteObject & defaultReadObject methods. Which methods does the part of saving an Object state manually & which does normal serialization?

What I understand is writeObject() & readObject() methods does the part of saving an Object state manually. defaultWriteObject & defaultReadObject methods
does normal serialization.

Please correct me if I am wrong or I forgot anything with respect to understand serialization mechanism. I appreciate your help.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We use readObject() and writeObject() to perform serialization in general.

However, when you want to perform manual serialization, you write your own private readObject() and writeObject() methods in your class.

Within your new readObject() you call defaultWriteObject() to perform serialization. Also in this method, we can manually write parts of some transient objects (or anything else) we may want to save using writeInt() etc.

Hope this helps in some way!
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neha, I am confuse about which methods are performing normal serialization & which are performing serialization for transient variable? Can you explain?
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Actually transient keyword will skill the serialization process, but
If we are using a transient keyword in java.How that variable will passed remotely.For example,i have class in which a variable 'password' is transient and this class implements serializable.When the object is passed remotely all the variables except password willget serializable.Then how does this variable password value will be retrieved at the end
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by dolly shah:
I am confuse about which methods are performing normal serialization & which are performing serialization for transient variable? Can you explain?



we cannot serialize transient variables..

normal serialization/deserialization is performed by writeObject() & readObject().

But when you have to do some custom writing and/or reading i.e. something that is not a part of that object graph we use defaultWriteObject() & defaultReadObject().
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Priyam. But in the book page:451, code doesn't show any dog object's serialization. As I understand Dog object goes immediately after private method & before defaultWriteObject().

If I am wrong, correct me.
 
Priyam Srivastava
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


this is the entire code of example on page 451...i hope you now understand what exactly is happening

As I understand Dog object goes immediately after private method & before defaultWriteObject().


can you be more precise on what you meant by the above statement?

In the above code first Dog object is saved and then we saved collarSize variable..
[ August 22, 2007: Message edited by: Priyam Srivastava ]
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Priyam. I got it now after spending couple of hours. Thanks again.
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Priyam,

Originally posted by Priyam Srivastava:
[CODE]But when you have to do some custom writing and/or reading i.e. something that is not a part of that object graph we use defaultWriteObject() & defaultReadObject().



Can you give me a practical example of some custom writing and/or reading. to understand exactly how defaultWriteObject() & defaultReadObject() behave ??

Thanks
[ April 28, 2008: Message edited by: Rahul Nair ]
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!