Skip to main content

customization creates null Elements

1 reply [Last post]
Joined: 2008-05-12

I'm trying to work with the <dom> JAXB customizations specified in JAXB 2.1 section 7.12. I want to have some elements of a schema left as plain old Elements so that I can stuff them in another object that takes a List<Element>. My problem is that the elements created from the <dom> customization are always null when XML is unmarshalled - even when the data should be there and is there without the customization. Has anyone experienced this or know why the Elements created by the <dom> customization aren't getting populated with w3c DOM elements? Let me know if I should attached some code and a schema.
Thanks in advance,

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-05-12

The behavior I describe can be observed by customizing the external-customize sample that ships with the JAXB RI. I just changed the USAddress customization in binding.xjb to use Elements with jxb:dom.
<jxb:bindings node="//xs:complexType[@name='USAddress']">
<jxb:dom />
JAXBContext jc = JAXBContext.newInstance("primer.myPo");
Unmarshaller u = jc.createUnmarshaller();
InputStream is = Main.class.getResourceAsStream("po.xml");
JAXBElement poe = (JAXBElement)u.unmarshal(is);
POType po = (POType)poe.getValue();
You'll notice that the po.getBillTo() returns null instead of exposing the w3c Element object. Is there any way to just have JAXB unmarshall into Element and not generated object types?