小编alv*_*gro的帖子

Spring RestTemplate和XMLStream与对象列表一起使用

我试图用来Spring RestTemplate检索员工记录列表,例如:

public List<Employee> getEmployeesByFirstName(String firstName) {   
return restTemplate.getForObject(employeeServiceUrl + "/firstname/{firstName}", List.class, firstName);
}
Run Code Online (Sandbox Code Playgroud)

问题是Web服务(被调用)返回以下XML格式:

<employees> <employee> .... </ employee> <employee> .... </ employee> </ employees>

所以当执行上面的方法时,我得到以下错误:

org.springframework.http.converter.HttpMessageNotReadableException: Could not read [interface java.util.List]; nested exception is org.springframework.oxm.UnmarshallingFailureException: XStream unmarshalling exception; nested exception is com.thoughtworks.xstream.mapper.CannotResolveClassException: **employees : employees**
Run Code Online (Sandbox Code Playgroud)

spring xstream resttemplate

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

resttemplate ×1

spring ×1

xstream ×1