我遇到了在另一個JAXB對象內映射JAXB對象集合的麻煩,任何人都會在下面看到我的結構有問題?我得到一個空的ArrayList formerUsers使用下面的代碼:JAXB嵌套集合
String test="<SSO-Request><User-Id>3119043033121014002</User-Id><Former-User-Ids><User-Id>3119043033121014999</User-Id><User-Id>3119043033121014555</User-Id></Former-User-Ids></SSO-Request>";
SSORequest ssoRequest=null;
try{
JAXBContext jaxbContext = JAXBContext.newInstance(SSORequest.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
ssoRequest = (SSORequest) unmarshaller.unmarshal(new StringReader(test));
}
catch(Exception e){
e.printStackTrace();
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="SSO-Request")
public class SSORequest {
@XmlElement(name="User-Id")
String userId;
@XmlElementWrapper(name="Former-User-Ids")
List<FormerUser> formerUsers;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="Former-User-Ids")
public class FormerUser {
@XmlElement(name="User-Id")
String userId;
}