title: Is Restlet returning 415 Unsupported Media Type when it should return 400 Bad Request?
body: <p>I'm using Restlet 2.1 with jackson to build a json REST api.</p>
  
  <p>When I make a request with the expected content type but a malformed body, I get back a 415 "Unsuppored Media Type" status code. I think the correct error code should be 400 "Bad Request".</p>
  
  <p>Apparently the mixup happens when Jackson tries and fails to decode the garbage.</p>
  
  <p>I'll try to make the case more clear with some code:</p>
  
  <pre><code>// java method mapping
  @Post("json")
  public Project create(Project project) {
  </code></pre>
  
  <p>The service invocation with curl</p>
  
  <pre><code>$ curl -i -XPOST -H 'content-type: application/json' -d '{xgarbage}' http://localhost:8080/projects HTTP/1.1 415 Unsupported Media Type
  </code></pre>
  
  <p>And a fragmente of the stack trace os recorde in the logs:</p>
  
  <pre><code>Nov 29, 2010 9:51:56 PM org.restlet.ext.jackson.JacksonRepresentation getObject
  WARNING: Unable to parse the object with Jackson.
  org.codehaus.jackson.JsonParseException: Unexpected character ('x' (code 120)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
   at [Source: java.io.ByteArrayInputStream@693e4a5a; line: 1, column: 2]
  at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:929)
  </code></pre>
  
  <p>The actual implementation of the service is never hit, so somewhere a decision is made to map the garbled content to a 415.</p>
  
  <p>Now, my question is: is this correct? If I'm reading correctly the following quotes from the book "RESTful Web Services", it is not, but I'm open to corrections.</p>
  
  <blockquote>
    <p>[400 Bad Request] It’s commonly used when the client submits a representation along with a PUT or POST request, and the representation is in the right format, but it doesn’t make any sense.</p>
  </blockquote>
  
  <p>.</p>
  
  <blockquote>
    <p>[415 Unsupported Media Type] If the client sends a document that’s got the right media type but the wrong format (such as an XML document written in the wrong vocabulary), a better response is the more generic 400 (“Bad Request”)</p>
  </blockquote>
  
  <p>Right or wrong, I'd prefer to return a 400.</p>
  
  <p>Is there a way to change the behaviour without renouncing at the auto-magic serialisation provided by Jackson?</p>
  
  <p>Any help is greatly appreciated,
  thanks!</p>