I have a simple Foo class saying like this:
public class Foo { @NotNull private String bar; public String getBar(){ return bar; } public void setBar(String _bar){ this.bar = _bar; } }
Now I have a REST controller method that accepts an Foos array (or collection), where I want each Foo to have a non-empty bar property. I thought using the @Valid annotation would do the trick, but it doesn't seem to be that way:
@Controller public class MyController { @RequestMapping(value="/foos", method=RequestMethod.POST) public @ResponseBody String createFoos(@Valid @RequestBody Foo[] foos){
Note. This does not work with the <Foo> or list. But with unique Foo, it works!
It seems that Spring validation does not work when we have "several" objects (in a collection or an array).
I even tried to implement HandlerMethodArgumentResolver with custom annotation, but I donβt know how to define "indexed property names" in BindingResult.
If someone knows a workaround for this problem, it would be quite helpful! :)
source share