gpt4 book ai didi

java - Rersteasy 异常 "No type information to extract entity with, use other getEntity() methods"

转载 作者:行者123 更新时间:2023-11-30 09:11:45 25 4
gpt4 key购买 nike

我在我的项目中使用了resteasy。我正在从我的其余网络功能返回一个 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 - Rersteasy 异常 "No type information to extract entity with, use other getEntity() methods",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21950670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com