Reputation: 86747
I'm creating a rest
service with spring
and want to offer a json
response:
@RequestMapping(value = "/test",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public MyResponse content() {
return rsp;
}
MyResponse
may contain null
values which should not be returned in the JSON
response (these params should just be removed).
@XmlRootElement
class MyResponse {
}
Is that possible?
Upvotes: 6
Views: 15083
Reputation: 1320
Globally remove null
property.
spring.jackson.default-property-inclusion = non_null
Upvotes: 7
Reputation: 613
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;
Upvotes: 18