How to set JAXB properties with JBossWS-CXF?

Solution Unverified - Updated -

Environment

  • JBoss Enterprise Application Platform (EAP) 6.x

Issue

  • I need to set a JAXB property on the JAXBContext like below. How can the JAXBContext used by JBossWS be accessed to have the configuration applied?
properties.put(JAXBRIContext.XMLACCESSORFACTORY_SUPPORT, true);
context = JAXBContext.newInstance(new Class[] { ....}, properties);

Resolution

Take a look at this page under JAXB Properties:

By setting the XML configuration here as shown in the example, you can provide a map of context properties. This map is then passed to the JAXBDataBinding.setContextProperties() method which is used to create the JAXBContext. When the JAXBContext is created, this property map will be passed to the JAXBContext's constructor so it basically inherits the properties you set:

public void setContextProperties(Map<String,Object> contextProperties)

Set a map of JAXB context properties. These properties are passed to JAXBContext.newInstance when this object creates a context.

Note that if a JAXB context is created elsewhere, you will not respect these properties unless you handle it manually.
Parameters:

contextProperties - map of properties

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments