MariuszS MariuszS - 1 year ago 69
Java Question

Howto pass XStream reference into camel for marshalling

Sample code from

If you would like to configure the XStream instance used by the Camel for the message transformation, you can simply pass a reference to that instance on the DSL level.

XStream xStream = new XStream();
xStream.aliasField("money", PurchaseOrder.class, "cash");
// new Added setModel option since Camel 2.14

marshal(new XStreamDataFormat(xStream)).

But this code is wrong, because
constructor accept only String. How to configure custom
in camel?

I dont want to use XML, my application is using Spring.

Answer Source

If you want to have it done fast, instead of going through "marshal" you can redirect to a marshalling "bean" that will do the marhsalling in the way you need.


Complete code

FooDeserializer fooDeserializer;

public RouteBuilder route() {
    return new RouteBuilder() {
        public void configure() {

public class FooDeserializer {

    private final XStream xStream;

    public FooDeserializer() {
        xStream = new XStream();
        xStream.aliasField("money", PurchaseOrder.class, "cash");

    public Foo xmlToFoo(String xml) {
        return (Foo) xStream.fromXML(xml);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download