JSR-380 adds support for validating containers elements (inside collections, optional) by annotating the parameterized type:
List<@Email String> emails;
Is there any way to get this to work in current versions (e.g. Spring MVC 4.3.8) of Spring MVC on controller methods? I've upgraded to Hibernate Validator 6.0.2 and Validation API 2.0.0 but I can't seem to get the following examples to work and I'm not sure if it's my misuse of the annotations, missing configuration or a lack of support in the framework:
@RequestMapping(value = "/emails", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public void emails(@Valid @RequestBody List<@Email String> emails) {
}
@RequestMapping(value = "/users", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public void users(@Valid @RequestBody List<@Valid User> users) {
}
(where User has @NotNull annotations on certain attributes)
I've tried with and without the @Valid before @RequestBody annotation.