下面的代码有效,所以我知道我得到了正确的回复文字:
{"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!
}