以下のコードは機能するので、正しい応答テキストを取得していることがわかります。
{"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!
}