You have the option to do with annotation at the class level, i.e:
@JsonInclude(Include.NON_NULL) //or Include.NON_EMPTY, if that fits your use case
public static class Request {
// ...
}
As noted in comments, in versions below 2.x the syntax for this annotation is:
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) // or JsonSerialize.Inclusion.NON_EMPTY
The other option is to configure the ObjectMapper directly, simply by calling
mapper.setSerializationInclusion(Include.NON_NULL);
As mentioned by drew moore
You maybe also can take a look on Ignore Null Fields with Jackson - Baeldung