How to remove empty or null nodes/arrays from the request body in java?

Viewed 74

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": "testHbFhO@mail7.io"
        }
    ],
    "password": "p@s$w0rD"
}

I want my request body to be sent as below:

{
   "email": [
        {
            "type": "primary",
            "value": "testHbFhO@mail7.io"
        }
    ],
    "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.

0 Answers
Related