使用gson,如何从序列化中排除具有默认值的数字类型(double,integer)? [英] Using gson, how to exclude a numeric type (double, integer) with default value from serialization?

查看:490
本文介绍了使用gson,如何从序列化中排除具有默认值的数字类型(double,integer)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gson进行序列化并遇到问题。在我定义的类Person中,有一个字段age,其类型为int。该字段默认为0,除非它稍后重置。在序列化Object的对象时,如果它的值仍然为0,我想排除字段age。有人可以告诉我如何使用gson来做到这一点吗?



谢谢,

建国

解决方案

gson自定义序列化 li>

  • 不包括字段


  • 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 to exclude the field "age" if it is value is still 0. Can anybody tell me how to do that using gson?

    Thanks,

    Jianguo

    解决方案

    这篇关于使用gson,如何从序列化中排除具有默认值的数字类型(double,integer)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆