title: Null request body not getting caught by Spring @RequestBody @Valid annotations
body: <p>I am currently running into an issue with the <code>@RequestBody</code> annotation in Spring. I currently have all my validation annotations set up on my models properly, and they work great when an object is POSTed. Everything works as expected even when the request body posted is completely empty or an empty object "{}". The problem arises when someone tries to post a request body of "null". This somehow gets through the <code>@Valid</code> annotation and is not caught, causing a <code>NullPointerException</code> when I try to access the object. I have pasted a snippet of my controller below.</p>
  
  <pre><code>@Secured({ ROLE_ADMIN })
  @RequestMapping(method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE } )
  public HttpEntity&lt;Resource&lt;Item&gt;&gt; addItem(@RequestBody @Valid Item item) throws Exception {
      Resource&lt;Item&gt; itemResource = this.itemResourceAssembler.toResource(this.itemService.save(item));
      return new ResponseEntity&lt;Resource&lt;Item&gt;&gt;(itemResource, HttpStatus.CREATED);
  }
  </code></pre>
  
  <p>I do some checks in <code>itemService.save()</code> to see if an item exists in the database already, since this is being used as an upsert. When I access the item passed to save I get the <code>NullPointerException</code> because item is null. I've tried using the "required" parameter of <code>@RequestBody</code> but that only checks to see if there was something POSTed. As stated above, the null item is only passed through when a user posts "null" without the quotes as the request body. Is there a automated Spring annotation or configuration to stop this null from being passed through, or should I just put <code>if(item == null) throw new Exception();</code> in all of my controllers where this could crop up?</p>