我在Rest方法上使用注释@BeanParam将JSON输入映射到我的bean。问题在于@BeanParam没有映射输入。
这是方法:
@POST
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String test(@Context HttpServletResponse servletResponse, @BeanParam MyBean mb)
MyBean.java:
public class MyBean{
@QueryParam("a")
private String a;
public MyBean(@QueryParam("a") String s) {
this.a= s;
}
public String getA() {
return a;
}
public void setA(String a) {
this.a= a;
}
}
我的pom.xml是:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javax-servlet.version>4.0.1</javax-servlet.version>
<jackson.version>2.9.7</jackson.version>
<version.jersey>2.25</version.jersey>
</properties>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax-servlet.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
我正在使用Java 8,Jersey 2.25和WildFly 14。 Rest服务类扩展了org.glassfish.jersey.server.ResourceConfig。
我不明白为什么不起作用。