Search code examples
serializationgsontransient

Adding Transient modifier to existing object


I have a Object Defined as

class MyObj {
        int a;
        String b;
        Date d;   //I will add the transient 
}

During serialization the object was without 'transient' and the serialized string contains the Date. Now I am adding the 'transient' modifier with the Date. Will it be able to deserialize?

I have tested with my machine and it is working but somehow I am not confident on this one. I am using Gson for serialize/deserialize.


Solution

  • No.!

    that is exactly the definition of transient keyword in java

    Quote

    transient is a Java keyword which marks a member variable not to be serialized when it is persisted to streams of bytes.transient is a Java keyword which marks a member variable not to be serialized when it is persisted to streams of bytes.