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):

enter image description here here project layout libraries: enter image description here

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

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

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -