I am actually new to REST WS but really I don\'t get this 415 Unsupported Media Type
.
I am testing my REST with Poster on Firefox and the GET
Add Content-Type: application/json
and Accept: application/json
in REST Client header section
I had this issue and found that the problem was that I had not registered the JacksonFeature class:
// Create JAX-RS application.
final Application application = new ResourceConfig()
...
.register(JacksonFeature.class);
Without doing this your application does not know how to convert the JSON to a java object.
https://jersey.java.net/documentation/latest/media.html#json.jackson
The issue is in the deserialization of the bean Customer. Your programs knows how to do it in XML, with JAXB as Daniel is writing, but most likely doesn't know how to do it in JSON.
Here you have an example with Resteasy/Jackson http://www.mkyong.com/webservices/jax-rs/integrate-jackson-with-resteasy/
The same with Jersey: http://www.mkyong.com/webservices/jax-rs/json-example-with-jersey-jackson/
just change the content-type to application/json when you use JSON with POST/PUT, etc...
I had the same problem:
curl -v -H "Content-Type: application/json" -X PUT -d '{"name":"json","surname":"gson","married":true,"age":32,"salary":123,"hasCar":true,"childs":["serkan","volkan","aybars"]}' XXXXXX/ponyo/UserModel/json
* About to connect() to localhost port 8081 (#0)
* Trying ::1...
* Connection refused
* Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 8081 (#0)
> PUT /ponyo/UserModel/json HTTP/1.1
> User-Agent: curl/7.28.1
> Host: localhost:8081
> Accept: */*
> Content-Type: application/json
> Content-Length: 121
>
* upload completely sent off: 121 out of 121 bytes
< HTTP/1.1 415 Unsupported Media Type
< Content-Type: text/html; charset=iso-8859-1
< Date: Wed, 09 Apr 2014 13:55:43 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact
* Closing connection #0
I resolved it by adding the dependency to pom.xml as follows. Please try it.
<dependency>
<groupId>com.owlike</groupId>
<artifactId>genson</artifactId>
<version>0.98</version>
</dependency>
I encountered the same issue in postman, i was selecting Accept in header section and providing the value as "application/json". So i unchecked and selected Content-Type and provided the value as "application/json". That worked!