java - POST to Jersey REST service getting error 415 Unsupported Media Type -
i using jax-rs web application jersey , tomcat. requests fine when try post json http status 415 - unsupported media type.
here simple helloworld.java:
package service; import javax.ws.rs.*; @path("hello") public class helloworld { @get @produces("text/plain") public string get() { return "hello world"; } @post @consumes("application/json") public string post(js input) { return input.hello; } public static class js { public string hello; } } here request try in postman (with 'application/json' header):
here project layout libraries: 
i using:
- java 7 x64
- jersey 2.17
- tomcat 7.0.62 x64
thanks!
the jersey distribution doesn't come json/pojo support out box. need add dependencies/jars.
add these
- jersey-media-json-jackson-2.17
- jackson-jaxrs-json-provider-2.3.2
- jackson-core-2.3.2
- jackson-databind-2.3.2
- jackson-annotations-2.3.2
- jackson-jaxrs-base-2.3.2
- jackson-module-jaxb-annotations-2.3.2
- jersey-entity-filtering-2.17
with maven, below pull above in
<dependency> <groupid>org.glassfish.jersey.media</groupid> <artifactid>jersey-media-json-jackson</artifactid> <version>2.17</version> </dependency> for future readers not using jersey 2.17 (and using jars directly instead of maven), can go here find jersey version using, , see transitive dependency versions need. current version of jersey dependency uses jackson 2.3.2. that's main thing need out for.
Comments
Post a Comment