title: Spring Bean Validation @Valid handling
body: <p>I have created a Spring MVC REST service using Bean Validation 1.2 with the following method:</p>
  <pre><code>@RequestMapping(value = &quot;/valid&quot;)
  public String validatedMethod(@Valid ValidObject object) {
  
  }
  </code></pre>
  <p>If object isn't valid, Tomcat informs me that <code>The request sent by the client was syntactically incorrect.</code> and my <code>validatedMethod</code> is never called.</p>
  <p>How can I get the message that was defined in the <code>ValidObject</code> bean? Should I use some filter or interceptor?</p>
  <p>I know that I can rewrite like below, to get the set of <code>ConstraintViolation</code>s from the injected <code>Validator</code>, but the above seems more neat...</p>
  <pre><code>@RequestMapping(value = &quot;/valid&quot;)
  public String validatedMethod(ValidObject object) {
      Set&lt;ConstraintViolation&lt;ValidObject&gt;&gt; constraintViolations = validator
              .validate(object);
      if (constraintViolations.isEmpty()) {
          return &quot;valid&quot;;
      } else {
          final StringBuilder message = new StringBuilder();
          constraintViolations.forEach((action) -&gt; {
              message.append(action.getPropertyPath());
              message.append(&quot;: &quot;);
              message.append(action.getMessage());
          });
          return message.toString();
      }
  }
  </code></pre>