使用RestEasy测试RESTFUL服务 - 无法转换为对象

时间:2016-03-20 12:40:32

标签: java rest resteasy java-ws

下面的代码有效,所以我知道我得到了正确的回复文字:

{"id":2,"name":"Liverpool"}

但是我想将响应放入Location类。那是我遇到问题的时候。如果我取消注释这一行

List <Location> location = response.readEntity(new GenericType<List<Location>>() {});

我遇到了问题(如果我不在列表中包含位置,则会出现问题)

javax.ws.rs.ProcessingException: Unable to find a MessageBodyReader of content-type application/json;charset=utf-8 and type interface java.util.List

任何想法?

@Test
public void testList() throws IOException {

//        Client client = ClientBuilder.newClient();

    Client client = ClientBuilder.newBuilder().build();
    WebTarget target = client.target("http://localhost:9000/location/1");
    Response response = target.request().get();
String value = response.readEntity(String.class);
    //List <Location> location = response.readEntity(new GenericType<List<Location>>() {});
    System.out.println(value);
   // System.out.println(location.size());
    response.close();  // You should close connections!
}

0 个答案:

没有答案