0

but it should retain the fields in other array elements which did not match the criteria. I have json response like below

{
    "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
}

when "anotherKey" value is "criteria", the "keyOne","keyTwo","keyThree" should be omitted, else it should be retained. any solution to this? thanks in advance

sidgate
  • 14,650
  • 11
  • 68
  • 119
Bond1705
  • 77
  • 1
  • 8
  • 1
    `someKey` looks like an object which on `Java` side probably is represented by a `POJO` class. Use `@JsonAnyGetter` annotation and implement method which will return map with required set of key-value pairs. See also: [Adding a dynamic json property as java pojo for jackson](https://stackoverflow.com/questions/56245719/adding-a-dynamic-json-property-as-java-pojo-for-jackson/56247021#56247021) – Michał Ziober Jun 26 '21 at 09:46
  • The response is from an Entity Class which is wrapped by `PageImpl`. so it possible to implement `@JsonAnyGetter` at entity level or should I use a TO? – Bond1705 Jun 28 '21 at 04:42
  • 1
    What do you mean by `TO`? You can use `@JsonAnyGetter` annotation on `Entity` level. – Michał Ziober Jun 28 '21 at 07:17
  • Transfer Object – Bond1705 Jun 28 '21 at 09:37
  • 1
    It depends from you, you can create a new `TO` or use `Entity`. These two options have it's own pros and cons. – Michał Ziober Jun 28 '21 at 10:35

0 Answers0