• Post Reply Bookmark Topic Watch Topic
  • New Topic

transient is confusing  RSS feed

 
Padmaja Godbole
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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.
 
zmarak ahmad djan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • 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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!