In a Spring MVC REST service (json), I have a controller method like this one :
@RequestMapping(method = RequestMethod.POST, value = { \"/doesntmatter\" })
Using com.google.common.collect.ForwardingList
public class ValidList extends ForwardingList {
private List<@Valid T> list;
public ValidList() {
this(new ArrayList<>());
}
public ValidList(List<@Valid T> list) {
this.list = list;
}
@Override
protected List delegate() {
return list;
}
/** Exposed for the {@link javax.validation.Validator} to access the list path */
public List getList() {
return list;
}
}
So no need for the wrapper
you may use
@RequestMapping(method = RequestMethod.POST, value = { "/doesntmatter" })
@ResponseBody
public List<...> myMethod(@Valid @RequestBody ValidList request, BindingResult bindingResult) {
By using wrapper your JSON needs to be changed to
{
"list": []
}
with this implementation you can use original JSON
[]