JAXB mappable XML elements

sirz01

New Member
In the root.class from my xi-schema, the element item and ohter objects are part of an itemList:\[code\]@XmlElementRef(name = "item", namespace = "xi", type = JAXBElement.class, required = false) //...protected List<Object> itemList;\[/code\]I've in the ObjectFactory.class from the main-schema some items as JAXBElements like this:\[code\]@XmlElementDecl(namespace = "de-schema", name = "detailedInformation", substitutionHeadNamespace = "xi", substitutionHeadName = "item")public JAXBElement<numItemType> createDetailedInformation(numItemType num) { return new JAXBElement<numItemType>(_detailedInformation_QNAME, numItemType.class, null, num);}\[/code\]So the numItemType has some attributes and value(num) for the JAXBElement. NumItemType.class:\[code\]@XmlJavaTypeAdapter(numItemTypeAdapter.class)@XmlAccessorType(XmlAccessType.FIELD)@XmlType(name = "numItemType", namespace = "xi", propOrder = { "num"})public class NumItemType { @XmlValue protected BigDecimal num; @XmlAttribute(name = "precision") protected String precision; @XmlAttribute(name = "decimals") protected String decimals; //... more Attributes}\[/code\]But when JAXB unmarshal the XML document, it will has only elements, for example:\[code\]<detailedInformation> <element1>1234</element1> <element2>5678</element2> <element3>bla</element3></detailedInformation>\[/code\]When I marshal it, it should become (like the JAXB java code):\[code\]<detailedInformation element2="5678" element3="bla">1234</detailedInformation>\[/code\]Therefore, I have written an numItemTypeAdapter.class with NumItemTypeAdapter extends XmlAdapterAdaptedNum.class:\[code\]public class AdaptedNum { @XmlElement private double element1; @XmlElement private String element2; @XmlElement private String element3; /** Some getter/setter methods */}\[/code\]I thought, that would be help me http://blog.bdoughan.com/2012/02/xmlanyelement-and-xmladapter.html, but it is all a bit tricky :-/
 
Back
Top