title: @Valid JSON request with BindingResult causes IllegalStateException
body: <p>I have a REST service which takes a JSON request. I want to validate the JSON request values that are coming in. How can I do that?</p>
  
  <p>In Spring 3.1.0 RELEASE, I know one wants to make sure they are using the latest support classes listed at <a href="http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/new-in-3.1.html#d0e1515">3.1.13 New HandlerMethod-based Support Classes For Annotated Controller Processing</a></p>
  
  <p>The old ones are items like: <code>AnnotationMethodHandlerAdapter</code>. I want to make sure I am using the latest such as <code>RequestMappingHandlerAdapter</code>.</p>
  
  <p>This is because I hope it fixes an issue where I see this:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!</p>
  </blockquote>
  
  <p>My <code>@Controller</code> handler method and associated code is this:</p>
  
  <pre><code>@Autowired FooValidator fooValidator;
  
  @RequestMapping(value="/somepath/foo", method=RequestMethod.POST)
  public @ResponseBody Map&lt;String, String&gt; fooBar(
          @Valid @RequestBody Map&lt;String, String&gt; specificRequest,
          BindingResult results) {
  
      out("fooBar called");
  
      // get vin from JSON (reportRequest)
  
      return null;
  }
  
  
  @InitBinder("specificRequest") // possible to leave off for global behavior
  protected void initBinder(WebDataBinder binder){
      binder.setValidator(fooValidator);
  }
  </code></pre>
  
  <p><code>FooValidator</code> looks like this:</p>
  
  <pre><code>@Component
  public class FooValidator  implements Validator {
  
      public boolean supports(Class&lt;?&gt; 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);
      }
  }
  </code></pre>
  
  <p>If I remove the <code>BindingResult</code>, everything works fine except I won't be able to tell if the JSON validated.</p>
  
  <p>I am not strongly attached to the concept of using a <code>Map&lt;String, String&gt;</code> for the JSON request or using a separate validator as opposed to a Custom Bean with validation annotation (How do you do that for a JSON request?). Whatever can validate the JSON request. </p>