我在我的项目中使用resteasy。我正在从我的其余 Web 函数返回一个 Response 对象。
@Override
public Response getData(@QueryParam(value = "test") String test) {
GenericEntity<List<UserEntity>> customerentities = new GenericEntity<List<UserEntity>>(result){};// result is the List<UserEntity>
return Response.ok(customerentities).build();
}
现在在我的 junit 测试用例中我正在做
Response response = testService.getData("testD");
response.getEntity() // doing this to retrive the List<UserEntity>
但出现以下错误
java.lang.RuntimeException:没有用于提取实体的类型信息,请使用其他 getEntity() 方法 在 org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:334)
有什么想法吗?
最佳答案
使用 getEntity()
时Resteasy 客户端上的方法,您需要通过 <T>
指定类型参数,否则需要调用其他重载之一 getEntity()
在方法签名中指定预期返回类型的方法。
ClientRequest request = new ClientRequest('RESOURCE URL HERE');
ClientResponse<List<UserEntity>> response = request.get(new GenericType<List<UserEntity>>(){});
List<UserEntity> users = response.getEntity();
关于java - Resteasy异常 "No type information to extract entity with, use other getEntity() methods",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21950670/