-------------- General type ------------------
public class Pair<KT, VT> {
private KT key;
private VT value;
public Pair() {
}
public Pair(KT key, VT value) {
this.key = key;
this.value = value;
}
}
------------- Restful API ------------
@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<Integer, String> pair){
return "put success : " + pair.toString();
}
}
------------- -------------- Problem
GET response: http: // localhost: 8080 / api / test / query :
{"key":{"type":"int","value":0},"value":{"type":"string","value":"value:0"}}
But, when I send the same json to POST: http: // localhost: 8080 / api / test / post with the header Content-Type: application / json, an exception occurs:

Can someone tell me how to publish a type object?
--------------- pom.xml ------------------
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>
</dependencies>
<properties>
<jersey.version>2.23.1</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>9.0.6.v20130930</jetty.version>
</properties>
source
share