1
如何使用Apache CXF休息客戶端將JSON響應字符串解組爲正確的對象?Apache CXF客戶端解組響應
下面是我的實現,它調用其餘的終點。我正在使用Apache CXF 2.6.14
請注意,響應狀態會告訴我要解組到哪個對象。
public Object redeem(String client, String token) throws IOException {
WebClient webClient = getWebClient();
webClient.path(redeemPath, client);
Response response = webClient.post(token);
InputStream stream = (InputStream) response.getEntity();
//unmarshal the value
String value = IOUtils.toString(stream);
if (response.getStatus() != 200) {
//unmarshall into Error object and return
} else {
//unmarshall into Token object and return
}
}