Does Spring support MVC support for JSR-380 (Bean validation 2)?

JSR-380 adds support for checking container elements (inside collections, optional) by annotating a parameterized type:

List<@Email String> emails; 

Is there a way to make this work in current versions (e.g. Spring MVC 4.3.8) from Spring MVC in controller methods? I upgraded to Hibernate Validator 6.0.2 and Validation API 2.0.0, but I can’t provide the following examples to work, and I’m not sure if this is due to the incorrect use of annotations, lack of configuration or lack of support within:

 @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 the user has @NotNull annotations for certain attributes)

I tried with and without @Valid before the @RequestBody annotation.

+5
source share

Source: https://habr.com/ru/post/1271609/


All Articles