开发者

Using gson, how to exclude a numeric type (double, integer) with default value from serialization?

开发者 https://www.devze.com 2023-02-17 13:11 出处:网络
I am using gson for serialization and running into a problem. In the class \"Person\" I defined, there is a field \"age\", whose type is \"int\". This field is defaulted to 0 unless it is reset later.

I am using gson for serialization and running into a problem. In the class "Person" I defined, there is a field "age", whose type is "int". This field is defaulted to 0 unless it is reset later. In serializing an object of Person, I want t开发者_如何学Goo exclude the field "age" if it is value is still 0. Can anybody tell me how to do that using gson?

Thanks,

Jianguo


  • gson custom serialization
  • excluding fields
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号