【问题标题】:How to eliminate variables with null value using JSON如何使用 JSON 消除具有空值的变量
【发布时间】:2015-08-27 09:05:39
【问题描述】:

我收到以下格式的 json 响应

{
    "employees": [
        {
            "emp_id": 101,
            "name": null,
            "company": "Onmobile",
            "test_beans": null
        },
        {
            "emp_id": 101,
            "name": null,
            "company": "Onmobile",
            "test_beans": null
        }
    ],
    "organizations": [
        {
            "name": "Google"
        },
        {
            "name": "Facebook"
        }
    ]
}

name 是 String 类型的属性,test_beans 是某个类的引用变量。因此,在获得响应时,我想排除那些具有空值的变量。 我正在使用spring rest-api。而且我有一个自定义 gsonconverter...所以请帮助我了解 gson builder 需要做什么,以便它可以消除那些空变量。

【问题讨论】:

    标签: java spring gson spring-rest


    【解决方案1】:

    只要您没有将 serializeNulls() 设置为 GsonBuilder,默认情况下会排除 Null 值。

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 2022-06-11
      • 2021-06-26
      • 1970-01-01
      • 2019-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多