RestTemplate为getForEntity调用返回null

时间:2016-04-08 20:09:32

标签: resttemplate spring-web

返回状态200,

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

和http标题:

{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]}

然而身体是空的。

我的包装器看起来像这样:

public class MyWrapper {
    private List<Object> junk;

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

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

如果我使用其中任何一种,我可以&#34;看到&#34;数据:

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

我有消息转换器:

    [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]

我的所有RestTemplate调用都会发生这种情况,我无法弄清楚它在不同环境中使用类似代码的原因。

我的REST响应看起来像这样:

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

1 个答案:

答案 0 :(得分:0)

啊,事实证明我需要将“数据”键更改为“垃圾”,然后它会在包装类中将其取出。

相关问题