5
的实体我有这样定义的JAX-RS服务:JAX-RS客户端返回null
@Produces(MediaType.APPLICATION_JSON)
@GET
@Path("/namestartswith")
public List<ProductBrand> nameStartsWith(@QueryParam("name") String name) {
List<ProductBrand> productBrandList = productBrandService.findByNameStartsWith(name);
System.out.println("productBrandList: " + productBrandList);
return productBrandList;
}
发出以下网址:
http://localhost:19191/productbrand/namestartswith?name=f
生产:
{"productBrand":[{"brandImage":"ffbrand.png","description":"the brand called ff","id":"1","name":"ffbrand"},{"brandImage":"flfl.png","description":"flfl","id":"6","name":"flfl"},{"brandImage":"ffbran.png","description":"ffbr","id":"16","name":"ffbran"}]}
这意味着该服务正按预期工作。
现在我使用RestEasy进行客户端访问。
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
下面的代码来访问服务:
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:19191/productbrand/namestartswith?name=" + name);
Response restEasyResponse = target.request(MediaType.APPLICATION_JSON).get();
log("entity: " + restEasyResponse.readEntity(new GenericType<List<ProductBrand>>() {
}););
的输出是:
实体:空
即使主叫restEasyResponse.getEntity()
返回null
。什么可能是错的?