I am calling a REST service with POST verb. Post request body is constructed dynamically.In some cases few fields will be populated with null values.Even though I used my Request pojo with @JsonInclude(Include.NON_NULL)
or @JsonInclude(JsonInclude.Include.NON_NULL)
null value fields are not getting removed.
My sample request will be looks like below.
I am constructing requestEntity by myself and not parsing it before posting.
resetTemplate.exchange(uri,HTTP.POST,requestEntity,responseObject)
How do I remover in the request body fileds with null value
I am using Spring Boot 1.5.9 and it uses Jackson 2.x
@JsonInclude(Include.NON_NULL)
should have worked for you!
You seem to be constructing the request entity by yourself and not sure if you are passing on a JSON string with NON_NULL. Try this instead directly with entity if you have annotated with Jackson annotations.
restTemplate.postForEntity(uri, requestDto, ResponseDto.class);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With