Skip to content

Support validating collection of objects on web controller method #16917

Closed as not planned
@spring-projects-issues

Description

@spring-projects-issues

Will May opened SPR-12312 and commented

Add support for being able to validate a list of objects similar to the example below, where Foo is a class which has various JSR 303 annotations on its fields:

@RequestMapping(value = "/foo", method = RequestMethod.POST)
public void insertFoos(@Valid @RequestBody List<Foo> foos) {
  ...
}

I've managed to partially implement the functionality by extending the LocalValidatorFactoryBean and setting the nested path to the current list path ([i]) while calling super.validate in a loop. This almost works apart from the fact that the BeanWrapper cannot retrieve an invalid value if one fails validation and so throws an exception while trying to throw an exception.

So, in summary, the BeanWrapper needs to be able to work directly on lists rather than only being able to work on objects containing lists.


Affects: 4.0.7

Issue Links:

1 votes, 4 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions