How to remove null parameters in a json rest response?
12,781
Solution 1
Try this :
@JsonInclude(JsonInclude.Include.NON_NULL)
class MyResponse {
...
}
You'll need to update your dependencies and import this :
import com.fasterxml.jackson.annotation.JsonInclude;
Solution 2
Globally remove null
property.
spring.jackson.default-property-inclusion = non_null
Author by
membersound
JEE + Frameworks like Spring, Hibernate, JSF, GWT, Vaadin, SOAP, REST.
Updated on June 27, 2022Comments
-
membersound almost 2 years
I'm creating a
rest
service withspring
and want to offer ajson
response:@RequestMapping(value = "/test", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public MyResponse content() { return rsp; }
MyResponse
may containnull
values which should not be returned in theJSON
response (these params should just be removed).@XmlRootElement class MyResponse { }
Is that possible?