1

下面的代码有效,所以我知道我得到了正确的响应文本:

{"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!
}
4

0 回答 0