title: Error handling with Spring and Jackson
body: <p>I have problems with generating proper error messages with Spring and Jackson. Scenario: A controller with a custom model a <code>@ResponseBody</code> (see below) a model with two attributes, that can possibly cause parsing errors. Now, I want to return a proper error message, if parsing of these fields fails (e.g. Got an invalid string for a <code>Date</code>).</p>
  
  <p>If a parsing error happens, Spring will catch it and returns a <code>400 Bad Request</code> response with HTML body. Though I am able to implement my own <code>HandlerExceptionResolver</code>, that catches this kind of exception to generate a meaningful error message. Unfortunately, I am only able to catch the first parsing error and not a possibly second one.</p>
  
  <p>So, is there a way to collect all parsing/deserialization errors and generate a proper error message with all problems?</p>
  
  <p>I am using Jackson 1.7.1 and Spring 3.2.2.</p>
  
  <hr>
  
  <p><strong>Some example code:</strong> </p>
  
  <p><em>TimeController.java</em></p>
  
  <pre class="lang-java prettyprint-override"><code>@Controller
  @RequestMapping("/time")
  public class TimeController {
      @RequestMapping(method = RequestMethod.POST)
      public @ResponseBody
      TimeDocument create(@RequestBody TimeDocument entity) {
          // magic
          return entity;
      }
  }
  </code></pre>
  
  <p><em>TimeDocument.java</em></p>
  
  <pre class="lang-java prettyprint-override"><code>public class TimeDocument {
      public String name;
      public Date date1;
      public Date date2;
  }
  </code></pre>
  
  <hr>
  
  <p><em>Request 1:</em> I will get an <code>200 OK</code>.</p>
  
  <pre><code>{
    "name": "test",
    "date1": 123,
    "date2": 1234
  }
  </code></pre>
  
  <p><em>Request 2:</em> I will get an <code>400 Bad Request</code>, but I am able to generate a proper error message like: "Date 1 has an invalid format.".</p>
  
  <pre><code>{
    "name": "test",
    "date1": "crap",
    "date2": 1234
  }
  </code></pre>
  
  <p><em>Request 3:</em> I will get an <code>400 Bad Request</code>, but I am not able to generate a proper error message like: "Date 1 has an invalid format. Date 2 has an invalid format.".</p>
  
  <pre><code>{
    "name": "test",
    "date1": "crap",
    "date2": "crap"
  }
  </code></pre>