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
}
}