我正在消耗一个宁静的春天,但我没有成功获得所有数据。
RESTful响应细节:
{
"errorCode": "0",
"errorMessage": "OK",
"transactionUUID": "2e48d6e7-f1fb-4271-b282-d74d3df1ef23",
"data":{
"price": "123",
"quantity" : "1",
"productname" : "Anystuff"}
}
我的课程:
public class ResponseRest{
private String errorCode;
private String errorMessage;
private String transactionUUID;
private ResponseDetail data;
//get and set methods
}
public class ResponseDetail {
private String price;
private String quantity;
private String productname;
//get and set methods
}
我的控制器类中的一部分方法:
HttpHeader headers;
//headers.set....
String jsonParam = "{\"transactionToken\":\""+transactionToken+"\","
+ "\"sessionToken\":\""+sessionToken+"\"}";
RestTemplate restTemplate = new RestTemplate();
HttpEntity<String> entity = new HttpEntity<String>(jsonParam, headers);
response = restTemplate.exchange(URL_API_AUTH, HttpMethod.POST, entity, ResponseRest.class);
当我通过控制台获得结果时,我只从ResponseRest类中获取属性,但不从ResponseDetail类中获取它们的详细信息,控制台结果:
System.out.println("-> Result - status ("+ response.getStatusCode() + ") has body with: " + (response.getBody().toString()));
结果 - 状态(200)的正文为:ResponseRest [errorCode =&#34; 0&#34;,errorMessage =&#34; OK&#34;,transactionUUID =&#34; 2e48d6e7-f1fb-4271-b282 -d74d3df1ef23&#34;,data [price = null,quantity = null,productname = null]]
我做错了什么?
非常感谢他们的时间。