java - JAXB Nesting a Collection -


I am having trouble creating a collection of JACAB objects within another JACAB object, with some of my structure Seeing the problem below? I get an empty pre-user array list using the following empty code:

  string test = "STO-request" gt; user-id & gt; 3119043033121014002 & lt; / User ID & gt; & lt; Pre-User-ID & gt; & lt; User-Id & gt; 3119043033121014999 & lt; / User-Id & gt; & lt; User-Id & gt; 3119043033121014555 & lt; / User-Id & gt; & lt; / Pre-User-ID & gt; & lt; / SS-request & gt; "; SSORequest ssoRequest = null; Try {JAXBContext jaxbContext = JAXBContext.newInstance (SSORequest.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller (); SsoRequest = (SSORequest) unmarshaller.unmarshal (new string reader (test)); } Hold (exception e) {e.printStackTrace (); } @ XmlAccessorType (XmlAccessType.FIELD) @ XmlRootElement (name = "SSO-request") public class SSORequest {@XmlElement (name = "user-id") string user id; @ XmlElementWrapper (name = "pre-user-id") list & lt; Pre-Users & gt; FormerUsers; } = XmlAccessorType (XmlAccessType.FIELD) @ XmlRootElement (name = "pre-user-id") public class former user {@XmlElement (name = "user-id") string userId; }    

You are reversing your mapping, all you need is this: @XmlAccessorType (XmlAccessType.FIELD) @ XmlRootElement (name = "SSO-request") public class SSORequest {@XmlElement (name = "User-Id") string userId; @XmlElementWrapper (name = "pre-user-id") @ XmlElement (name = "user-id") list & lt; String & gt; FormerUserIds; }

Comments