...
This example shows how to configure the data type just once and reuse it on multiple routes. For Camel versions below 1.5.0 you have to set the <jaxb> element directly in <camelContext>.
Wiki Markup |
---|
{snippet:id=example|lang=xml|url=camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/marshalAndUnmarshalWithRef.xml} |
...
If you use XJC to create the java class from the schema, you will get an ObjectFactory for you JAXB context. Since the ObjectFactory uses JAXBElement to hold the reference of the schema and element instance value, from Camel 1.5.1 jaxbDataformat will ignore the JAXBElement by default and you will get the element instance value instead of the JAXBElement object form the unmarshaled message body.
If you want to get the JAXBElement object form the unmarshaled message body, you need to set the JaxbDataFormat object's ignoreJAXBElement property to be false.
Setting encoding
In Camel 1.6.1 and newer you You can set the encoding option to use when marshalling. Its the Marshaller.JAXB_ENCODING
encoding property on the JAXB Marshaller.
You can setup which encoding to use when you declare the JAXB data format. You can also provide the encoding in the Exchange property Exchange.CHARSET_NAME
. This property will overrule the encoding set on the JAXB data format.
...
Code Block |
---|
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jaxb</artifactId> <version>1<version>x.6x.0<x</version> </dependency> |