我不明白爲什麼當我收到一個json編碼的字符串時,它不會自動解碼。 我嘗試使用Apache CFX 3.1.4或澤西2.22.1驗證碼:使用Java REST客戶端(Apache CXF或Jersey)讀取字符串
Client client = ClientBuilder.newClient().register(JSONProvider.class);
WebTarget target = client.target("http://example.org/rest/service1");
target = target.queryParam("method", "method1");
Entity<EndpointRequest> entity = Entity.entity(new EndpointRequest("0000"),
MediaType.APPLICATION_JSON);
Response response = target.request()
.accept(MediaType.APPLICATION_JSON)
.post(entity);
System.out.println(response.getStatus());
if (response.getStatus() == 200) {
// The problem comes here
String basePath = response.readEntity(String.class);
System.out.println(basePath);
}
成功執行的請求,但basePath
包含"\/opt\/local\/application\/rest\/"
(反斜槓和雙引號包含)
basePath
應改爲包含此: /opt/local/application/rest/
在我看來,json反序列化並沒有被觸發。
可能是JSON序列化程序的問題。 –