I have the following XML-Data, generated by liferay-Portal 6.2 for journal-articles:
<root available-locales="de_DE" default-locale="de_DE">
<dynamic-element name="Begriff" index="0" type="text" index-type="keyword">
<dynamic-content language-id="de_DE"><![CDATA[Transition]]></dynamic-content>
</dynamic-element>
<dynamic-element name="Abkürzung" index="0" type="text" index-type="keyword">
<dynamic-content language-id="de_DE"><![CDATA[]]></dynamic-content>
</dynamic-element>
<dynamic-element name="Synonyme" index="0" type="text" index-type="keyword">
<dynamic-content language-id="de_DE"><![CDATA[]]></dynamic-content>
</dynamic-element>
<dynamic-element name="Text" index="0" type="text_area" index-type="keyword">
<dynamic-content language-id="de_DE"><![CDATA[<p>...</p>
<p>Beispielsweise wird d...</p>]]></dynamic-content>
</dynamic-element>
</root>
How can I get a POJO from that XML using Jackson-Annotation
I started with something like the following:
@XmlRootElement
@JsonIgnoreProperties(ignoreUnknown=true)
public class BlogEntryContent implements Serializable {
@JacksonXmlElementWrapper(localName = "dynamic-element")
private List<DynamicElement> dynamicElement= new ArrayList<>();
// Constructors
public BlogEntryContent() {
}
//Getters an Setters
...
and the class DynamicElement:
@JsonIgnoreProperties(ignoreUnknown=true)
public class DynamicElement implements Serializable {
@JacksonXmlElementWrapper(localName = "dynamic-content")
private List<DynamicContent> dynamicContent = new ArrayList<>();
//Constructors
public DynamicElement() {
}
public DynamicElement(List<DynamicContent> dynamicContent) {
this.dynamicContent = dynamicContent;
}
//Getters and Setters
...
But that does not really work :-(
@pratik directed me to the right way. The correct code looks like following:
@JsonIgnoreProperties(ignoreUnknown=true)
@JacksonXmlRootElement(localName = "root")
public class BlogContent {
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "dynamic-element")
List dynElem;
//Constructor
...
//Getters
...
}
Important is to set the rootname with @JacksonXmlRootElement(localName = "root") and to set the JacksonXmlElementWrapper(useWrapping = false), because there is no wrapper in the xml ! @XmlRootElement(name = "root") works also!