-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate values in top-level Map parameters [SPR-14615] #19182
Comments
Juergen Hoeller commented There is no standard support for validating top-level |
Martin Asenov commented
|
Juergen Hoeller commented You could inject an |
Martin Asenov commented thanks, I'll give it a try, even though it is not comprehensible to me why such basic functionality is not supported. |
Juergen Hoeller commented Agreed, it is unintuitive that this doesn't work. This is partially due to the JavaBean nature of both the Bean Validation spec and Spring's data binding, where collections and maps are only defined to be nested within top-level objects. Simply speaking, we're just passing the given object to |
Martin Asenov commented I coulnd't get the suggested approach to work too. @Autowired
private Validator validator;
@RequestMapping(value = "/", method = RequestMethod.POST)
public void postMethod(@RequestBody Map<String, CustomDto> rules, Errors errors) {
rules.values().forEach(value -> {validator.validate(value, errors)});
} stiill doesn't detect the missing Thanks |
This is now supported with Bean Validation and the built-in Spring web method validation #30645. |
Martin Asenov opened SPR-14615 and commented
Class with RestController annotation
Method with RequestMapping annotation, method is POST
Map<String, CustomDto> is a parameter, annotated with
@Valid
and@RequestBody
CustomDto has
@NotNull
on one of its fields.The input passes even though a CustomDto entry is not valid (null value on the
@NotNull
field)When I try to change the Map with a single CustomDto, it is validated correctly, but when a map, it is not.
Affects: 4.2.5
Issue Links:
@Validated
support on Iterables (and implementors)1 votes, 3 watchers
The text was updated successfully, but these errors were encountered: