首页 > 解决方案 > 有没有办法根据spring boot中的条件从JSON响应内容的JSON数组的匹配数组元素中省略某些字段

问题描述

但它应该保留与条件不匹配的其他数组元素中的字段。我有如下的json响应

{
    "content": [
        {
            "someId": 1498,
            "someKey": {
                "anotherKey": "Not Specified",
                "keyOne": "",
                "keyTwo": null,
                "keyThree": null
            },
            "date": "2009-09-11",
            "time": "17:14",
            "location": "Not Specified"
        },
        {
            "someId": 1498,
            "someKey": {
                "anotherKey": "criteria",
                "keyOne": "some data",
                "keyTwo": "some data for key two",
                "keyThree": "some data for key three"
            },
            "date": "2009-09-12",
            "time": "17:15",
            "location": "Not Specified"
        },...
    ],
    "pageable": {
        "sort": {
            "sorted": false,
            "unsorted": true,
            "empty": true
        },
        "offset": 0,
        "pageSize": 10,
        "pageNumber": 0,
        "unpaged": false,
        "paged": true
    },
    "totalElements": 10630,
    "totalPages": 1063,
    "last": false,
    "size": 10,
    "number": 0,
    "sort": {
        "sorted": false,
        "unsorted": true,
        "empty": true
    },
    "first": true,
    "numberOfElements": 10,
    "empty": false
}

当“anotherKey”值为“criteria”时,“keyOne”、“keyTwo”、“keyThree”应省略,否则应保留。有什么解决办法吗?提前致谢

标签: jsonserializationfilterjackson

解决方案


推荐阅读