I want to bind a XML content as a String to the field.
Here is how my xml seems like:
<sample>
<content>
<p>here is content <b>with bold</b></p>
</content>
</sample>
which should be bound to the following domain object:
@Entity
@Table(name="news_table")
@XmlRootElement
class Sample {
@XmlElement(name="content")
@Column(name="news_content")
private String content;
}
After unmarshalling, i want to bind the content starts with <p> as String type in order to persist formatted text with HTML tags, so that:
System.out.println(sample.getContent());
must give the following out:
> "<p>here is content <b>with bold</b></p>"
With @XmlElement annotation i get only empty string “” back from binding operation, since the JAXB recognize the element starts with “<p>” as Object to be bound according to my understanding.
Any suggestion ?
Try using
@XmlAnyElementannotation with a customDomHandler. You can find an example here.