...
The following example shows how to use JAXB to unmarshal using Spring configuring the jaxb data type
Wiki Markup |
---|
{snippet:id=example|lang=xml|url=camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/springDataFormat.xml} |
Wiki Markup |
---|
{snippet:id=example|lang=xml|url=camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/marshalAndUnmarshalWithRef.xml} |
Tip | ||
---|---|---|
| ||
It is possible to use this data format with more than one context path. You can specify context path using |
...
This feature is new to Camel 2.2.0.
JAXB 2 supports marshalling and unmarshalling XML tree fragments. By default JAXB looks for @XmlRootElement
annotation on given class to operate on whole XML tree. This is useful but not always - sometimes generated code does not have @XmlRootElement annotation, sometimes you need unmarshall only part of tree.
In that case you can use partial unmarshalling. To enable this behaviours you need set property partClass
. Camel will pass this class to JAXB's unmarshaler.
Wiki Markup |
---|
{snippet:id=example|lang=xml|url=camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/springDataFormatPartial.xml} |
partNamespace
attribute with QName of destination namespace. Example of Spring DSL you can find above....
In this Spring DSL we have defined to use iso-8859-1
as the encoding:
Wiki Markup |
---|
{snippet:id=example|lang=xml|url=camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/springDataFormatWithEncoding.xml} |
Controlling namespace prefix mapping
...
mustBeJAXBElement
you can set to false, to relax this check, so the JAXB marshaller only attempts to marshal JAXBElements (javax.xml.bind.JAXBIntrospector#isElement returns true). And in those situations the marshaller fallbacks to marshal the message body as-is.XmlRootElement objects
Available as of Camel 2.17.2
The JAXB Data Format option objectFactory has a default value equals to false. This is related to a performance degrading. For more information look at the issue CAMEL-10043
For the marshalling of non-XmlRootElement JaxB objects you'll need to call JaxbDataFormat#setObjectFactory(true)
Dependencies
To use JAXB in your camel routes you need to add the a dependency on camel-jaxb which implements this data format.
...