如何从Java的请求主体中删除空节点/数组?

发布于 2025-02-09 16:09:20 字数 1057 浏览 1 评论 0原文

这是我在Java的要求,我从Pojo那里得到了。

我已经使用@jsoninclude(value = jsoninclude.include.non_null) in phonenumber,country,电子邮件,地址,地址类。但这不是删除节点。

如何删除Phonenumber,Country,Email,地址节点/阵列?

{
    "phoneNumbers": [
        {
            
        }
    ],
    "country": {
        
    },
    "addresses": [
        {
            
        }
    ],
    "email": [
        {
            "type": "primary",
            "value": "[email protected]"
        }
    ],
    "password": "p@s$w0rD"
}

我希望我的请求主体如下:

{
   "email": [
        {
            "type": "primary",
            "value": "[email protected]"
        }
    ],
    "password": "p@s$w0rD"
}

这将是一个动态 post 请求,因此我正在寻找动态解决方案,不想硬编码Phonenumber,Country Country等节点。

This is my request body in java, I am getting this from POJO.

I've used @JsonInclude(value = JsonInclude.Include.NON_NULL) in phonenumber, country, email, addresses class. But It is not removing the node.

How can I remove phonenumber, country, email, addresses nodes/arrays?

{
    "phoneNumbers": [
        {
            
        }
    ],
    "country": {
        
    },
    "addresses": [
        {
            
        }
    ],
    "email": [
        {
            "type": "primary",
            "value": "[email protected]"
        }
    ],
    "password": "p@s$w0rD"
}

I want my request body to be sent as below:

{
   "email": [
        {
            "type": "primary",
            "value": "[email protected]"
        }
    ],
    "password": "p@s$w0rD"
}

This would be a dynamic POST request, so I am looking for a dynamic solution, do not want to hardcode the phonenumber, country etc nodes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文