alv*_*gro 8 spring xstream resttemplate
我试图用来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)
Mad*_*ker 16
你可能正在寻找这样的东西:
public List<Employee> getEmployeeList() {
Employee[] list = restTemplate.getForObject("<some URI>", Employee[].class);
return Arrays.asList(list);
}
Run Code Online (Sandbox Code Playgroud)
应该使用自动编组正确编组.
| 归档时间: |
|
| 查看次数: |
10891 次 |
| 最近记录: |