title: Spring jackson deserialization and exception handling
body: <p>I'm building a REST api in Spring and I have problems with my exception handling. I want to  validate the full request and give information about the payload in one go.</p>
  
  <p>Suppose my object is</p>
  
  <pre><code>public class StubJson {
      private BigDecimal bigDecimalField;
      @NotEmpty
      private String stringField;
  
      public void setBigDecimalField(BigDecimal bigDecimalField) { this.bigDecimalField = bigDecimalField; }
      public String setStringField(String stringField) { this.stringField = stringField; }
  }
  </code></pre>
  
  <p>And my controller is</p>
  
  <pre><code>@RestController
  public class StubController {
      @RequestMapping(value = "/stub", method = POST)
      public void stub(@Valid @RequestBody StubJson stubJson) {}
  }
  </code></pre>
  
  <p>The validation on this object is in a @ControllerAdvice that translates FieldError objects into translated errors for the end user.</p>
  
  <pre><code>@ResponseStatus(BAD_REQUEST)
  @ResponseBody
  @ExceptionHandler(value = MethodArgumentNotValidException.class)
  public List&lt;ErrorJson&gt; processValidationError(MethodArgumentNotValidException ex) {}
  </code></pre>
  
  <p>If I pass in this json</p>
  
  <pre><code>{"bigDecimalField": "text", "stringField": ""}
  </code></pre>
  
  <p>I want a response like this</p>
  
  <pre><code>[
    {
      "field": "stringField",
      "message": "Cannot be empty."
    },
    {
      "field": "bigDecimalField",
      "message": "Not a number."
    }
  ]
  </code></pre>
  
  <p>If I do this I get a </p>
  
  <blockquote>
    <p>com.fasterxml.jackson.databind.exc.InvalidFormatException</p>
  </blockquote>
  
  <p>on the BigDecimalField which only contains information about <em>only one</em> field. The only option I see is passing it in as a String or writing custom validation annotations. Is there an easier way of achieving this?</p>