使用 Spring Rest 模板调用 Rest Web 服务,如下所示:
ResponseEntity<String> response = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, String.class);
并以字符串格式获取输出
<Info xmlns="http://schemas.test.org/2009/09/Tests.new" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<FirstName>FirstName</FirstName>
<LastName>LastName</LastName>
<TestGuid>Guid</TestGuid>
<TestUID>1</TestUID>
<Token>token</Token>
<TestUserID>14</TestUserID>
</Info>
尝试将其解组为 java 类时,如下所示
ResponseEntity<Info> response = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, Info.class)
Info 类定义为
@XmlRootElement(name = "Info", namespace = "http://schemas.test.org/2009/09/Tests.new")
public class Info implements Serializable{
private String firstName;
private String lastName;
private String testGuid;
private String testUID;
private String token;
private String testUserID;
//getters and setter
}
获取信息类 null 的所有值,例如 Firstname=null..
谁能告诉我缺少什么?谢谢