简体   繁体   English

如何使用JSON消除具有空值的变量

[英]How to eliminate variables with null value using JSON

I am getting json response in below format 我收到以下格式的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 is an attribute of type String and test_beans is a reference variable of some class. name是String类型的属性,而test_beans是某个类的引用变量。 So, while getting a response I want to exclude those variables which are having null value. 因此,在获得响应时,我想排除那些具有空值的变量。 I am using spring rest-api. 我正在使用spring rest-api。 And I have a custom gsonconverter...so please help me on what needs to do with gson builder so it can eliminate those null variables. 而且我有一个自定义的gsonconverter ...所以请帮助我处理gson builder需要做什么,以便它可以消除那些null变量。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM