I need to convert xml file to java objects.
<PRODUCT id="10" name="Notebook">
<VALUE id="30" type="Formatted">This is mixed <TUNIT style="style-12">formatted</TUNIT> text value.</VALUE>
</PRODUCT>
Here is Product class:
@Getter
@Setter
@XmlRootElement(name = "PRODUCT")
@XmlAccessorType(XmlAccessType.FIELD)
public class Product {
@XmlAttribute(name = "id")
private String id;
@XmlAttribute(name = "name")
private String name;
@XmlElementRef(name = "VALUE")
private Value value;
}
Here is Value class:
@Getter
@Setter
@XmlRootElement(name = "VALUE")
@XmlAccessorType(XmlAccessType.FIELD)
public class Value {
@XmlAttribute(name = "id")
private String id;
@XmlAttribute(name = "type")
private String type;
@XmlValue
private String content;
@XmlElementRef(name = "TUNIT")
private Tunit tunit;
}
Here is Tunit class:
@Getter
@Setter
@XmlRootElement(name = "TUNIT")
@XmlAccessorType(XmlAccessType.FIELD)
public class Tunit {
@XmlAttribute(name = "style")
private String style;
@XmlValue
private String content;
}
When I set @XmlAttribute for <VALUE> attribute id, @XmlValue for <VALUE> content, and @XmlElementRef for <TUNIT> - I'm getting an error:
If a class has @XmlElement property, it cannot have @XmlValue property.
Is it possible to unmarshal this xml with JAXB?