Marshal EIP

The Marshal and Unmarshal EIPs are used for Message Transformation.

Camel has support for message transformation using several techniques. One such technique is Data Formats, where marshal and unmarshal comes from.

So in other words the Marshal and Unmarshal EIPs are used with Data Formats.

  • Marshal - Transforms the message body (such as Java object) into a binary or textual format, ready to be wired over the network.

  • Unmarshal - Transforms data in some binary or textual format (such as received over the network) into a Java object; or some other representation according to the data format being used.

Example

The following example reads XML files from the inbox/xml directory. Each file is then transformed into Java Objects using JAXB. Then a Bean is invoked that takes in the Java object.

Then the reverse operation happens to transform the Java objects back into XML also via JAXB, but using the unmarshal operation. And finally the message is routed to a JMS queue.

from("file:inbox/xml")
  .marshal().jaxb()
  .to("bean:validateOrder")
  .unmarshal().jaxb()
  .to("jms:queue:order");

And in XML:

<route>
  <from uri="file:inbox/xml"/>
  <marshal><jaxb/></marshal>
  <to uri="bean:validateOrder"/>
  <unmarshal><jaxb/></unmarshal>
  <to uri="jms:queue:order"/>
</route>