我有一个带有一些方法的 RESTful 服务。方法由@POST
和注释@Consumes(MediaType.APPLICATION_JSON)
。
我有请求参数的包装器:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class RequestWrapper {
@XmlElement
private SomeInfo someInfo = new SomeInfo();
@XmlElement
@XmlElementWrapper
private List<RequestParameter> requestParameters = new ArrayList<>();
}
public class SomeInfo {
public String field1;
public String field2;
}
public class RequestParameter {
public String key;
public String value;
}
我向我的服务提出请求。POST 消息的正文:
{"someInfo":{"field1":"b","field2":"c"},"requestParameters":[{"key":"1","value":"2"},{"key":"3","value":"4"}]}
我看到someInfo
通过 RequestWrapper 处理和访问的值。但是List<RequestParameter> requestParameters
长度为零。
正常处理的消息怎么办?
PS 我使用 Glassfish 4.0。maven模块的依赖:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-processing</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>