I am getting an xml from an api and I want to be able to map it directly into a pojo, but the structure of the xml is as follows:
<xml>
<meta-info>
<meta name="id" content="1234-5678"/>
<meta name="title" content="test"/>
<meta name="fileType" content="txt"/>
<meta name="priority" content="low"/>
</-info>
</xml>
And I want to be able to map it to an object that has
String Id;
String title;
String fileType;
String priority;
I have tried using the XmlPath annotations:
@XmlRootElement(name="xml")
@XmlType(propOrder={"id", "title", "fileType", "priority"})
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlMapTest {
@XmlPath("xml[@name='id']")
private String id;
@XmlPath("xml[@name='title']")
private String title;
@XmlPath("xml[@name='fileType']")
private String fileType;
@XmlPath("xml[@name='priority']")
private String priority;
}
But I always get the same error:
"com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "meta-info" (class hibernateTests.XmlMapTest), not marked as ignorable (0 known properties: ])"
In all the other examples that I have seen, the example only takes the info from the name attribute, not from the content.
Is there away to do this directly?