I am working to hit API through Rest Template and I have successfully received the response in responseEntity form. Now my requirement is to extract values from response to my object.
String uri = "http://192.168.1.113:10100/scf/reset";
String str = "ship";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>();
map.add("scfType", str);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
ResponseEntity<String> response = restTemplate.exchange( uri, HttpMethod.POST, request, String.class);
And I have response in the form of JSON
{
"statusCode": 200,
"status": "OK",
"payload": {
"channelItemId": 41179181,
"itemQuantity": 6,
"date_Created": "2022-08-23T21:40:52.412+0000",
"date_Modified": "2022-09-20T11:15:40.859+0000",
"deleted": false,
"user_Id": 2075
}
I have my object which is
ChannelItem channelItem = new ChannelItem();
My requirement is to get values which are in payload
and store them in channelItem
.