• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

transient is confusing

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a class as follows :



and a test class as follows




Now my confusion(question) is

Even if I have marked refrence serialTest a as transient, I am able to serialize is. How it is possible?

If any one can answer this will be of gerat help, Thanks in advance.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a filed marked transient is not serialiazed by the serialisation mechanism
that serialize the enclosing Object.

in your example you serialize explicitly the field "a"
so it should work that way!
transient is not a sticky marker to object "a" it's something
that is operating when serializing the ENCLOSING object.
 
Padmaja Godbole
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the prompt reply but can you please be little bit more elaborate.

How can I surpress some objects of class serialTest from being serialized
For example : "a" in our case.
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, SerialTestWriter serializes objects of type SerialTest. The transient modifier indicates that a field of the object being serialized should not be included in the serialized object. Your transient field of type SerialTest is a field of SerialTestWriter. If you were to serialize SerialTestWriter then that field would not be serialized with it.

If you want to see how transient works then make one of the fields of your SerialTest class transient and check that out.

Hope that helps.

Jules
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Padmaja Godbole seems to be thinking that "transient" somehow changes the object that "a" is pointing to, and as Julian points out (if you read between the lines) this is not true. "transient" tells the Serialization mechanism how to treat a particular field of an object when that object itself is being serialized, and nothing more.
 
Padmaja Godbole
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh my god, yes it is so simple but I just started testing transient with wrong perception.

If you were to serialize SerialTestWriter then that field would not be serialized with it.


and I was serializing SerialTest and was expecting that it should not get serialized.

Thanks a lot Julian.
 
reply
    Bookmark Topic Watch Topic
  • New Topic