How to have the Jackson serializer fail on required attributes that are null

Viewed 2270

I would like the Jackson JSON serializer to fail if it encounters required attributes that are null.

I know I can tell it to omit null fields (mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)). However, in addition I'd like to declare

@NotNull // BeanValidation
private String foo;

or

@JsonProperty(required = true) // Jackson databinding
private String foo;

and have the serializer fail if such fields are null.

1 Answers
Related