Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Custom DataFormat

You can use your custom Data Format implementation with Camel. All you have to do is to implement the DataFormat interface. For example in the following we will implement a reverse data format as shown below:

Wiki Markup
{snippet:id=e2|title=Custom implementation of DataFormat that reverses data|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/impl/RefDataFormatTest.java}

And to use it in Java DSL:

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/impl/RefDataFormatTest.java}

Notice we use custom to refer to the Data Format in the Registry. In Java DSL you can also provide the instance directly as shown:

Code Block
from("direct:a")
    .marshal(new MyReverseDataFormat())
    .to("mock:a");

And likewise to use it in XML DSL:

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/SpringRefDataFormatTest.xml}

Notice in the XML DSL example above we use <custom> to refer to a custom data format. This requires Camel 2.8 or better. In older releases you would have to use the ref attribute as shown below. Notice the ref attribute has been @deprecated and you should prefer to use the <custom> way:

Code Block
xml
xml
 <marshal ref="reverse"/>
Include Page
Endpoint See Also
Endpoint See Also