I am using Restlet 2.1 with jackson to create json REST api.
When I make a request with the expected content type, but with a distorted body, I return the status code 415 "Unsuppored Media Type". I think the correct error code should be 400 "Bad Request".
Mixing seems to occur when Jackson tries and cannot decode the garbage.
I will try to make the code more understandable with some code:
@Post("json")
public Project create(Project project) {
Service call with curl
$ curl -i -XPOST -H 'content-type: application/json' -d '{xgarbage}' http://localhost:8080/projects HTTP/1.1 415 Unsupported Media Type
And fragmentation of the os recorde stack trace in the logs:
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)
The actual implementation of the service is never hit, so somewhere a decision was made to map the distorted content to number 415.
, : ? "RESTful Web Services", , .
[400 Bad Request] , PUT POST, , .
.
[415 Unsupported Media Type] , , (, XML, ), 400 ( " " ")
, 400.
, , Jackson?
,
!