When I invoke a REST service (GET) from postman, it retrieves the result. But when tried to consume the service from code, I dont' get the data as expected. I suspect it has something to do with the JSON/POJO mapping. I tried it different ways but does not give the result. What could be possibly wrong here?
Here is my json response when I try from postman
[
{
"id": 20,
"type": 2,
"data": {
"name": "car"
}
},
{
"id": 20,
"type": 2,
"data": {
"name": "car"
}
}
]
Here is my pojo:
class Market{
public int id;
public int type;
public MarketData data;
}
class MarketData {
public Strig name;
}
And here is how I consume the service:
HttpClient client = HttpClients.custom().build();
HttpUriRequest request = RequestBuilder.get()
.setUri("url")
.setHeader(HttpHeaders.CONTENT_TYPE, "application/json")
.setHeader(HttpHeaders.ACCEPT, "application/json")
.build();
HttpResponse response = client.execute(request);
if (response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatusLine().getStatusCode());
}
ObjectMapper mapper = new ObjectMapper();
MarketData[] marketData = mapper.readValue(response.getEntity().getContent(), MarketData[].class);

mapper.readValue(response.getEntity().getContent(), Market[].class);?