I am trying to convert the below XML string to a Java object using JAXB and eclipse persistence oxm annotations package.
<output>
<rtEvent>
<eventData name="tcppayload">
<data>111111-000000-111111</data>
</eventData>
<eventData name="text">
<data>ABCD</data>
</eventData>
</rtEvent>
</output>
However, the de-serialization does not seem to work. Can someone point out what I might be doing wrong.
Below is the class i'm using to deserialize the string into an object
@XmlRootElement(name = "output")
@XmlAccessorType(XmlAccessType.FIELD)
public class CameraTriggerOutput {
@XmlPath("/rtEvent/eventData[@name=tcppayload]/data/text()")
private String data;
public void toXml() {
try {
JAXBContext ctx = JAXBContext.newInstance(CameraTriggerOutput.class);
Marshaller marshaller = ctx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(this, System.out);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
After running I get the following output
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><output/>