0

I have pinpointed where the issue is happening but having hard time resolving it .

My Json Response is such

{
{...},
{...},
{...}

}

This is my current code to retrieve the response.

ResponseEntity<Object[]> responseEntity  = restTemplate.getForEntity("http://api.walmartlabs.com/v1/nbp?apiKey={apiKey}&itemId={itemID}", Object[].class,WalmartAPIKey.APIKey,productId);
ProductRecommendations[] pra = (ProductRecommendations[]) responseEntity.getBody();

I can also see the array in responseEntity.getBody() but the issue is I am unable to map it to a POJO gives me type casting error.

Is there a way to get around it or do it a better way?

Praveen
  • 101
  • 14
  • What you have there doesn't look like valid JSON. An object must have keys and values, not just values. I guess what you get is in fact an array. Also, what would you do with an array of objects. You probably want something much more specific, like a List. Read http://stackoverflow.com/a/31947188/571407 – JB Nizet Jun 05 '16 at 17:47
  • I am on same post as the one you mentioned. When I try doing a Array of Products on responseEntity.getBody() I get class cast exception – Praveen Jun 05 '16 at 17:52
  • I linked specifically to the second answer, which doesn use arrays at all. Use a List, and a new ParameterizedTypeReference>, as shown in the specific response I linked to. – JB Nizet Jun 05 '16 at 17:54

0 Answers0