1

The structure of JSON looks like:

{
 "id": "0001",
 "type": "portable",
 "name": "mobile",
 "results":[
   { 
    "company": "Apple",
    "country": "US", 
    "city": "Cupertino"
   },
   { 
    "company": "Google",
    "country": "Japan", 
    "city": "Tokyo"
   }
  ]
}

I tried to map the above json to my "Response" class but I could only retrieve id, type and name. For json object "results" is shows results:[]. Here is the code I have implemented;

CompanyDetail class:

@JsonIgnoreProperties(ignoreUnknown = true)
public class CompanyDetail {
    public String company;
    public String country;
    public String city;

   //getters and setters
}

Company class:

    @JsonIgnoreProperties(ignoreUnknown = true)
public class CompanyD {
    public String name;
    public List<Detail> result;

   //getters and setters
}

Implementation class:

  @Override
  public ResponseEntity<String> getResponseEntity() {       
      RestTemplate restTemplate = new RestTemplate();
      ResponseEntity<String> response = restTemplate .getForEntity(
      "url", String.class);       
      logger.info("Response:"+response);
      return response;
}

    @Override
    public Company getResponseObject() {
        RestTemplate restTemplate=new RestTemplate();
        Company comp=(Company) restTemplate.getForObject("url",
                     Company.class,200);
        List<CompanyDetail> companyInfo = comp.getCompanyDetail();
        for (CompanyDetail companyDetail : companyInfo) {
            logger.info("Country:"+companyDetail.getCountry());
            logger.info("City:"+companyDetail.getCity());
            logger.info("Company:"+companyDetail.getCompany());
        }
    return comp;

From both the implementation method I am getting null values for the "results" json object. I could not figure out what is wrong with my code.

Thanks in advance.

1
  • Possible Duplicate of this Commented Feb 14, 2017 at 8:16

1 Answer 1

0

I'm having the same issue however in your case it looks like you misspelled "resluts".

Sign up to request clarification or add additional context in comments.

1 Comment

I corrected the spelling but still I am facing the same issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.