I am consuming a restful with spring but I do not achieve get all data successfully.
RESTful response detail:
{
"errorCode": "0",
"errorMessage": "OK",
"transactionUUID": "2e48d6e7-f1fb-4271-b282-d74d3df1ef23",
"data":{
"price": "123",
"quantity" : "1",
"productname" : "Anystuff"}
}
My classes:
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
}
Piece of my method in my controller class:
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);
When I got result by console, I only get the properties from the ResponseRest class but not their detail from class ResponseDetail, console result:
System.out.println("-> Result - status ("+ response.getStatusCode() + ") has body with: " + (response.getBody().toString()));
Result - status (200) has body with: ResponseRest[errorCode="0", errorMessage="OK",transactionUUID="2e48d6e7-f1fb-4271-b282-d74d3df1ef23", data[price=null,quantity=null,productname=null]]
What I doing wrong?
Thanks a lot for their time.