Search code examples
resttemplatespring-web

RestTemplate returning null for getForEntity call


This returns status 200,

final ResponseEntity<MyWrapper> responseEntity  = rt.getForEntity(
            myURL, MyWrapper.class);

and http headers:

{X-Powered-By=[Servlet/3.0], Content-Type=[application/json; charset=UTF-8], Cache-Control=[no-store], Transfer-Encoding=[chunked], Date=[Fri, 08 Apr 2016 20:03:11 GMT]}

however the body is null.

My wrapper looks like this:

public class MyWrapper {
    private List<Object> junk;

    public List<Object> getJunk() {
        return isspCases;
    }

    public void setJunk(List<Object> junk) {
        this.junk = junk;
    }
} 

If I use either of these, I can "see" the data:

rt.getForObject(caseListingURL, String.class);
rt.getForObject(caseListingURL, Map.class);

I have message converters:

    [org.springframework.http.converter.ByteArrayHttpMessageConverter@a96d56c   ,
org.springframework.http.converter.StringHttpMessageConverter@6ab4a5b,
 org.springframework.http.converter.ResourceHttpMessageConverter@2abe9173,
 org.springframework.http.converter.xml.SourceHttpMessageConverter@235d29d6, 
org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter@1fdca564, 
org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter@43f9dd56, 
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@1d12e953, null, null, null]

This happens with all my RestTemplate calls and I can't figure out why it works with similar code in a different environment.

My REST response looks something like this:

{"data":[{"a":"b"}, {"a":"c"}, {"a":"d"}]}

Solution

  • Ah it turns out that I need to change the "data" key to "junk" and it will then pick it up in the wrapper class.