Setting default value in GSON

Tarun :

Could someone tell why the following suggested solution to set default value on object while deserializing is working:
https://stackoverflow.com/a/30219311/35917

As per my understanding GSON does not use getter and setter method to set/fetch object property. I tried the solution on my system and it does not seem to be working.

Regards,

rxn1d :

Well, it doesn't, but you would want to access fields of the object you are trying to deserialize. And you will probably do so using getters.

In the provided answer getter will set a default value to the field if it finds that field is null. It's not really related go GSON, but can be applied to any java class.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=389069&siteId=1