My goal is to validate a JSON request. I am using Spring 3.1.0
This was an issue but I thought was fixed in (3.1 M2) https://jira.springsource.org/browse/SPR-6709
In the comments below, Rossen Stoyanchev says to make sure that you are using the latest stuff by "switching to the support classes" listed at http://static.springsource.org/sprin...1.html#d0e1515
How do I make sure I am using the new support classes such as RequestMappingHandlerAdapter?
To represent the JSON request, I have a Map<String, String> which works fine without validation. When I try to add validation, I get an
In my @Controller, I have a handler method and InitBinder that looks like this:Code:java.lang.IllegalStateException: Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!
Code:@Autowired FooValidator fooValidator; @RequestMapping(value="/somepath/foo", method=RequestMethod.POST) public @ResponseBody Map<String, String> fooBar( @Valid @RequestBody Map<String, String> specificRequest, BindingResult results) { System.out.println("fooBar called"); // get vin from JSON (reportRequest) return null; } @InitBinder("specificRequest") protected void initBinder(WebDataBinder binder){ binder.setValidator(fooValidator); }
My FooValidator looks like this:
Thanks for your prompt assistance! (I hope to code this by Thursday (tomorrow)!)Code:@Component public class FooValidator implements Validator { public boolean supports(Class<?> clazz) { out("supports called "); return Map.class.equals(clazz); } public void validate(Object target, Errors errors) { out("validate called "); } private void out(String msg) { System.out.println("****** " + getClass().getName() + ": " + msg); } }


Reply With Quote
