title: How to post generic type in jersey?
body: <p>--------------Generic Type------------------</p>
  
  <pre><code>public class Pair&lt;KT, VT&gt; {
      private KT key;
      private VT value;
  
      public Pair() {
      }
  
      public Pair(KT key, VT value) {
          this.key = key;
          this.value = value;
      }
  }
  </code></pre>
  
  <p>-------------Restful API------------</p>
  
  <pre><code>@Path("/test")
  public class TestApi {
      @GET
      @Path("/query")
      @Produces(MediaType.APPLICATION_JSON)
      public Pair query(@DefaultValue("0") @QueryParam("key") int key) {
          return new Pair(key, "value:" + key);
      }
  
      @POST
      @Path("/post")
      @Consumes(MediaType.APPLICATION_JSON)
      public String create(Pair&lt;Integer, String&gt; pair){
          return "put success : " + pair.toString();
      }
  }
  </code></pre>
  
  <p>-------------Problem--------------</p>
  
  <p>Response of GET : <a href="http://localhost:8080/api/test/query" rel="nofollow noreferrer">http://localhost:8080/api/test/query</a> is:</p>
  
  <p><code>{"key":{"type":"int","value":0},"value":{"type":"string","value":"value:0"}}</code></p>
  
  <p>But, when I post the same json to POST : <a href="http://localhost:8080/api/test/post" rel="nofollow noreferrer">http://localhost:8080/api/test/post</a> with "Content-Type: application/json" header, exception occurs:
  <a href="https://i.stack.imgur.com/4Okwg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Okwg.png" alt="enter image description here"></a></p>
  
  <p>Can anyone tell me how to post a generic type object?</p>
  
  <p>---------------pom.xml------------------</p>
  
  <pre><code>    &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
              &lt;version&gt;${jersey.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-client&lt;/artifactId&gt;
              &lt;version&gt;${jersey.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-common&lt;/artifactId&gt;
              &lt;version&gt;${jersey.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-container-servlet-core&lt;/artifactId&gt;
              &lt;version&gt;${jersey.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
              &lt;version&gt;2.7.5&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.jaxrs&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-jaxrs-json-provider&lt;/artifactId&gt;
              &lt;version&gt;2.7.4&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-media-json-jackson&lt;/artifactId&gt;
              &lt;version&gt;${jersey.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.test-framework.providers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-test-framework-provider-grizzly2&lt;/artifactId&gt;
              &lt;version&gt;${jersey.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;jetty-servlet&lt;/artifactId&gt;
              &lt;version&gt;${jetty.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;jetty-webapp&lt;/artifactId&gt;
              &lt;version&gt;${jetty.version}&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;properties&gt;
          &lt;jersey.version&gt;2.23.1&lt;/jersey.version&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;jetty.version&gt;9.0.6.v20130930&lt;/jetty.version&gt;
      &lt;/properties&gt;
  </code></pre>