Rersteasy exception "No type information to extract entity with, use other getEntity() methods"

StackOverflow https://stackoverflow.com/questions/21950670

  •  15-10-2022
  •  | 
  •  

سؤال

I am using resteasy in my project. I am returning an Response object from my rest webfunction.

@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();
}

Now in my junit test case I am doing

Response response = testService.getData("testD");
response.getEntity() // doing this to retrive the List<UserEntity>

But getting the below error

java.lang.RuntimeException: No type information to extract entity with, use other getEntity() methods at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:334)

any idea ?

هل كانت مفيدة؟

المحلول

When using the getEntity() method on the Resteasy client you need to specify the type via <T> parameter, otherwise you need to call one of the other overloaded getEntity() methods that specify the expected return type in the method signature.

   ClientRequest request = new ClientRequest('RESOURCE URL HERE');
   ClientResponse<List<UserEntity>> response = request.get(new GenericType<List<UserEntity>>(){});
   List<UserEntity> users = response.getEntity();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top