I am trying to convert xml to my Java class
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Request")
public class Request {
@XmlElement(name="UserName")
private String username;
@XmlElement(name="Password")
private String password;
@XmlElement(name="XMLPost")
private String xmlPost;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getXmlPost() {
return xmlPost;
}
public void setXmlPost(String xmlPost) {
this.xmlPost = xmlPost;
}}
Here is my context
JAXBContext jc = JAXVContext.newInstance(Request.class, Report.class, Status.class);
StringReader reader = new StringReader(xml);
Unmarshaller unmarshaller = jc.createUnmarshaller();
And here is how I use them together
Request request = unmarshaller.unmarshal(reader);
In the Request
class the xmlPost
will contain either xml of Report
or xml of Status
So I would like to capture it into a string so that I can try to unmarshal each case.
The Report
class comes from a 3rd party request that I have no control over. However when I attempt to unmarshal the Request
if there is any XML in XMLPost
field it tries to unmarshal it as well, even though I have specified that it should just be a String
. Why can't I stuff the xml that in XMLPost
in to a String
?
Thanks for all the help in advanced.