Search code examples
javaandroidjsongsontransient

Does a variable with transient property gets assigned with value if JSON string has that variable?


I'm not very familiar with serializations especially in relation to transient property so I want to know whether a variable with transient property gets assigned with a value if the JSON string being serialized contains that keyword/variable with corresponding value.

lets say I have a JSON:

"json": { "title": "TEST", "date": "2015-07-20" }

and I have a class:

public class MyClass {
    protected String title;
    protected transient String date;
}

will the variable date receive the value of date in the JSON when I use GSON's fromJson() method?

EDIT: just to clear things out, I don't plan to use the GsonBuilder, just the default settings it has. I just really wanna know about how it handles my stated case


Solution

  • no it will not. From the the documentation

    if a field is marked transient, (by default) it is ignored and not included in the JSON serialization or deserialization.

    you can find it here