Reputation: 21
Getting External API As below image- [1]: https://i.sstatic.net/a28Y1.png
{
"status" : 200,
"data" : [
{
"_id": "StringValue1",
"itmId": "StringValue1",
"itmName": "StringValue1",
"imgFileName":"StringValue1",
"imgFile":"byte[] data"
},
{
"_id": "StringValue2",
"itmId": "StringValue2",
"itemName": "StringValue2",
"imgFileName":"StringValue2",
"imageFile":"byte[] data2"
}
],
"message":""
}
Used as data array object.
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Response {
public String status;
Data [] data;
public String message
}
Another Object is below
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Data{
public String _id;
public String itmid;
public String itmName;
public String imgFileName;
byte [] imgFile;
}
Used /getForObject/exchange/getForEntity but not getting any response. Pls check at bottom method I used.
Now used as List of Data Object also not getting any response-
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Response {
public String status;
List<Data> data;
public String message
}
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Data{
public String _id;
public String itmid;
public String itmName;
public String imgFileName;
byte [] imgFile;
}
Here how called these by resttemplate-
Tried all the possible ways, but not getting any response from external rest API.
Please note response json conatin data[] where we have byte data for image. Need support and help pls..
Can any one support on this? Thanks in advance.
Upvotes: 0
Views: 421
Reputation: 892
You can achieve what you are looking by following:
ResponseEntity<List<Data>> responseEntity =
restTemplate.exchange(
BASE_URL,
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<Data>>() {}
);
List<Data> data = responseEntity.getBody();
Please let me know if it helps
Upvotes: 0