title: Spring MVC/Jackson: how to ask Spring to validate the JSON object in the request body?
body: <p>I'm using Spring MVC 3.2.3 + Jackson 2.1.4 for JSON serialization.</p>
  
  <p>I would like to known if it's possible to <strong>ask Spring to validate the JSON object in the request body*, especially if a required field is missing</strong> ?</p>
  
  <p>I tries to set <em>@JsonProperty(require = true)</em> on one attribute of the Java bean but no exception seems to be raised when the field is missing in the JSON object of the request.</p>
  
  <p>JSON in request body (missing "field1")</p>
  
  <pre><code>{
      "field2": "value2",
      "field3": "value3"
  }
  </code></pre>
  
  <p>Controller code :</p>
  
  <pre><code>@Controller
  @RequestMapping("/myBaseUrl")
  public class MyController{
  
      //...
  
      @RequestMapping(method = RequestMethod.POST, value = "/myUrl", consumes = MediaType.APPLICATION_JSON_VALUE)
      public void handle(@RequestBody MyRequestBean requestBean) throws IOException {
  
          // code reach at execution whereas I expected the throw of an exception because "field1" is missing in JSON.
      }
  }
  </code></pre>
  
  <p>Bean for the request:</p>
  
  <pre><code>public class MyRequestBean {
      //...
  
      @JsonProperty(required = true)
      private String field1
  
      //...
  
      public String getField1(){ return field1; }
      public void setField1(String field1){ this.field1 = field1; }
  }
  </code></pre>