Author: hadrian Date: Thu Jul 8 20:35:28 2010 New Revision: 961922 URL: http://svn.apache.org/viewvc?rev=961922&view=rev Log: CAMEL-2915. Patch for camel-xstream applied with thanks to Mark
Added: camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/PurchaseHistory.java camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.java camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/XStreamConfigurationTest.java camel/trunk/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/PurchaseOrder.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java?rev=961922&r1=961921&r2=961922&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/XStreamDataFormat.java Thu Jul 8 20:35:28 2010 @@ -71,12 +71,20 @@ public class XStreamDataFormat extends D setEncoding(encoding); } + public String getEncoding() { + return encoding; + } + public void setEncoding(String encoding) { this.encoding = encoding; } - public String getEncoding() { - return encoding; + public String getDriver() { + return driver; + } + + public void setDriver(String driver) { + this.driver = driver; } public List<String> getConverters() { Modified: camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java?rev=961922&r1=961921&r2=961922&view=diff ============================================================================== --- camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java (original) +++ camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java Thu Jul 8 20:35:28 2010 @@ -18,15 +18,20 @@ package org.apache.camel.dataformat.xstr import java.io.InputStream; import java.io.OutputStream; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import javax.xml.stream.XMLStreamException; import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import org.apache.camel.Exchange; import org.apache.camel.converter.jaxp.StaxConverter; +import org.apache.camel.spi.ClassResolver; import org.apache.camel.spi.DataFormat; /** @@ -40,18 +45,20 @@ public abstract class AbstractXStreamWra private XStream xstream; private StaxConverter staxConverter; - + private List<String> converters; + private Map<String, String> aliases; + private Map<String, String[]> implicitCollections; + public AbstractXStreamWrapper() { - } public AbstractXStreamWrapper(XStream xstream) { this.xstream = xstream; } - public XStream getXStream() { + public XStream getXStream(ClassResolver resolver) { if (xstream == null) { - xstream = createXStream(); + xstream = createXStream(resolver); } return xstream; } @@ -59,11 +66,37 @@ public abstract class AbstractXStreamWra public void setXStream(XStream xstream) { this.xstream = xstream; } - - protected XStream createXStream() { - return new XStream(); + + protected XStream createXStream(ClassResolver resolver) { + xstream = new XStream(); + + try { + if (this.implicitCollections != null) { + for (Entry<String, String[]> entry : this.implicitCollections.entrySet()) { + for (String name : entry.getValue()) { + xstream.addImplicitCollection(resolver.resolveMandatoryClass(entry.getKey()), name); + } + } + } + + if (this.aliases != null) { + for (Entry<String, String> entry : this.aliases.entrySet()) { + xstream.alias(entry.getKey(), resolver.resolveMandatoryClass(entry.getValue())); + } + } + + if (this.converters != null) { + for (String converter : this.converters) { + xstream.registerConverter(resolver.resolveMandatoryClass(converter, Converter.class).newInstance()); + } + } + } catch (Exception e) { + throw new RuntimeException("Unable to build Xstream instance", e); + } + + return xstream; } - + public StaxConverter getStaxConverter() { if (staxConverter == null) { staxConverter = new StaxConverter(); @@ -73,12 +106,44 @@ public abstract class AbstractXStreamWra public void setStaxConverter(StaxConverter staxConverter) { this.staxConverter = staxConverter; - } - + } + + public List<String> getConverters() { + return converters; + } + + public void setConverters(List<String> converters) { + this.converters = converters; + } + + public Map<String, String> getAliases() { + return aliases; + } + + public void setAliases(Map<String, String> aliases) { + this.aliases = aliases; + } + + public Map<String, String[]> getImplicitCollections() { + return implicitCollections; + } + + public void setImplicitCollections(Map<String, String[]> implicitCollections) { + this.implicitCollections = implicitCollections; + } + + public XStream getXstream() { + return xstream; + } + + public void setXstream(XStream xstream) { + this.xstream = xstream; + } + public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception { HierarchicalStreamWriter writer = createHierarchicalStreamWriter(exchange, body, stream); try { - getXStream().marshal(body, writer); + getXStream(exchange.getContext().getClassResolver()).marshal(body, writer); } finally { writer.close(); } @@ -87,13 +152,15 @@ public abstract class AbstractXStreamWra public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { HierarchicalStreamReader reader = createHierarchicalStreamReader(exchange, stream); try { - return getXStream().unmarshal(reader); + return getXStream(exchange.getContext().getClassResolver()).unmarshal(reader); } finally { reader.close(); } } - - protected abstract HierarchicalStreamWriter createHierarchicalStreamWriter(Exchange exchange, Object body, OutputStream stream) throws XMLStreamException; - protected abstract HierarchicalStreamReader createHierarchicalStreamReader(Exchange exchange, InputStream stream) throws XMLStreamException; + protected abstract HierarchicalStreamWriter createHierarchicalStreamWriter( + Exchange exchange, Object body, OutputStream stream) throws XMLStreamException; + + protected abstract HierarchicalStreamReader createHierarchicalStreamReader( + Exchange exchange, InputStream stream) throws XMLStreamException; } Modified: camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java?rev=961922&r1=961921&r2=961922&view=diff ============================================================================== --- camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java (original) +++ camel/trunk/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/XStreamDataFormat.java Thu Jul 8 20:35:28 2010 @@ -31,6 +31,7 @@ import com.thoughtworks.xstream.io.xml.S import com.thoughtworks.xstream.io.xml.StaxWriter; import org.apache.camel.Exchange; +import org.apache.camel.spi.ClassResolver; import org.apache.camel.spi.DataFormat; /** @@ -60,9 +61,9 @@ public class XStreamDataFormat extends A /** * A factory method which takes a collection of types to be annotated */ - public static XStreamDataFormat processAnnotations(Iterable<Class<?>> types) { + public static XStreamDataFormat processAnnotations(ClassResolver resolver, Iterable<Class<?>> types) { XStreamDataFormat answer = new XStreamDataFormat(); - XStream xstream = answer.getXStream(); + XStream xstream = answer.getXStream(resolver); for (Class<?> type : types) { xstream.processAnnotations(type); } @@ -72,9 +73,9 @@ public class XStreamDataFormat extends A /** * A factory method which takes a number of types to be annotated */ - public static XStreamDataFormat processAnnotations(Class<?>... types) { + public static XStreamDataFormat processAnnotations(ClassResolver resolver, Class<?>... types) { XStreamDataFormat answer = new XStreamDataFormat(); - XStream xstream = answer.getXStream(); + XStream xstream = answer.getXStream(resolver); for (Class<?> type : types) { xstream.processAnnotations(type); } Added: camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/PurchaseHistory.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/PurchaseHistory.java?rev=961922&view=auto ============================================================================== --- camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/PurchaseHistory.java (added) +++ camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/PurchaseHistory.java Thu Jul 8 20:35:28 2010 @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.dataformat.xstream; + +import java.util.List; + +public class PurchaseHistory { + + private List<Double> history; + + public List<Double> getHistory() { + return history; + } + + public void setHistory(List<Double> history) { + this.history = history; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((history == null) ? 0 : history.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + PurchaseHistory other = (PurchaseHistory) obj; + if (history == null) { + if (other.history != null) { + return false; + } + } else if (!history.equals(other.history)) { + return false; + } + return true; + } +} Modified: camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/PurchaseOrder.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/PurchaseOrder.java?rev=961922&r1=961921&r2=961922&view=diff ============================================================================== --- camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/PurchaseOrder.java (original) +++ camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/PurchaseOrder.java Thu Jul 8 20:35:28 2010 @@ -34,15 +34,16 @@ public class PurchaseOrder { @Override public boolean equals(Object o) { if (o instanceof PurchaseOrder) { - PurchaseOrder that = (PurchaseOrder)o; - return ObjectHelper.equal(this.name, that.name) && ObjectHelper.equal(this.amount, that.amount) - && ObjectHelper.equal(this.price, that.price); + PurchaseOrder that = (PurchaseOrder) o; + return ObjectHelper.equal(this.name, that.name) + && ObjectHelper.equal(this.amount, that.amount) + && ObjectHelper.equal(this.price, that.price); } return false; } public int hashCode() { - return (int)(name.hashCode() + (price * 100) + (amount * 100)); + return (int) (name.hashCode() + (price * 100) + (amount * 100)); } public double getAmount() { Added: camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.java?rev=961922&view=auto ============================================================================== --- camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.java (added) +++ camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.java Thu Jul 8 20:35:28 2010 @@ -0,0 +1,45 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.dataformat.xstream; + +import org.apache.camel.CamelContext; +import org.apache.camel.Service; +import org.apache.camel.spring.SpringCamelContext; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class SpringXStreamConfigurationTest extends XStreamConfigurationTest { + + protected CamelContext createCamelContext() throws Exception { + setUseRouteBuilder(false); + + final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( + "org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml"); + + setCamelContextService(new Service() { + public void start() throws Exception { + applicationContext.start(); + } + + public void stop() throws Exception { + applicationContext.stop(); + } + }); + + return SpringCamelContext.springCamelContext(applicationContext); + } +} Added: camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/XStreamConfigurationTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/XStreamConfigurationTest.java?rev=961922&view=auto ============================================================================== --- camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/XStreamConfigurationTest.java (added) +++ camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/XStreamConfigurationTest.java Thu Jul 8 20:35:28 2010 @@ -0,0 +1,164 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.dataformat.xstream; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.thoughtworks.xstream.converters.Converter; +import com.thoughtworks.xstream.converters.MarshallingContext; +import com.thoughtworks.xstream.converters.UnmarshallingContext; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.dataformat.XStreamDataFormat; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * Marshal tests with domain objects. + */ +public class XStreamConfigurationTest extends CamelTestSupport { + + @Test + public void testCustomMarshalDomainObject() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(2); + + PurchaseOrder order = new PurchaseOrder(); + order.setName("Tiger"); + order.setAmount(1); + order.setPrice(99.95); + List<Double> list = new ArrayList<Double>(); + list.add(11.5); + list.add(97.5); + + String ordereString = "<?xml version='1.0' encoding='UTF-8'?>" + + "<purchase-order name=\"Tiger\" price=\"99.95\" amount=\"1.0\"/>"; + mock.expectedBodiesReceived(new Object[] {ordereString, order}); + + template.sendBody("direct:marshal", order); + template.sendBody("direct:unmarshal", ordereString); + + mock.assertIsSatisfied(); + } + + @Test + public void testCustomMarshalDomainObjectWithImplicit() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(2); + + PurchaseHistory history = new PurchaseHistory(); + List<Double> list = new ArrayList<Double>(); + list.add(11.5); + list.add(97.5); + history.setHistory(list); + + String ordereString = "<?xml version='1.0' encoding='UTF-8'?>" + + "<org.apache.camel.dataformat.xstream.PurchaseHistory>" + + "<double>11.5</double><double>97.5</double>" + + "</org.apache.camel.dataformat.xstream.PurchaseHistory>"; + mock.expectedBodiesReceived(new Object[] {ordereString, history}); + + template.sendBody("direct:marshal", history); + template.sendBody("direct:unmarshal", ordereString); + + mock.assertIsSatisfied(); + } + + @Test + public void testCustomMarshalDomainObjectJson() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(2); + + PurchaseOrder order = new PurchaseOrder(); + order.setName("Tiger"); + order.setAmount(1); + order.setPrice(99.95); + List<Double> list = new ArrayList<Double>(); + list.add(11.5); + list.add(97.5); + + String ordereString = "{\"purchase-order\":{\"@name\":\"Tiger\",\"@price\":\"99.95\",\"@amount\":\"1.0\"}}"; + mock.expectedBodiesReceived(new Object[] {ordereString, order}); + + template.sendBody("direct:marshal-json", order); + template.sendBody("direct:unmarshal-json", ordereString); + + mock.assertIsSatisfied(); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + XStreamDataFormat xstreamDefinition = new XStreamDataFormat(); + Map<String, String> aliases = new HashMap<String, String>(); + aliases.put("purchase-order", PurchaseOrder.class.getName()); + xstreamDefinition.setAliases(aliases); + + List<String> converters = new ArrayList<String>(); + converters.add(PurchaseOrderConverter.class.getName()); + xstreamDefinition.setConverters(converters); + + Map<String, String[]> implicits = new HashMap<String, String[]>(); + implicits.put(PurchaseHistory.class.getName(), new String[] {"history"}); + xstreamDefinition.setImplicitCollection(implicits); + + from("direct:marshal").marshal(xstreamDefinition).to("mock:result"); + from("direct:unmarshal").unmarshal(xstreamDefinition).to("mock:result"); + + xstreamDefinition = new XStreamDataFormat(); + xstreamDefinition.setDriver("json"); + aliases = new HashMap<String, String>(); + aliases.put("purchase-order", PurchaseOrder.class.getName()); + xstreamDefinition.setAliases(aliases); + + converters = new ArrayList<String>(); + converters.add(PurchaseOrderConverter.class.getName()); + xstreamDefinition.setConverters(converters); + from("direct:marshal-json").marshal(xstreamDefinition).to("mock:result"); + from("direct:unmarshal-json").unmarshal(xstreamDefinition).to("mock:result"); + } + }; + } + + public static class PurchaseOrderConverter implements Converter { + + public boolean canConvert(Class type) { + return PurchaseOrder.class.isAssignableFrom(type); + } + + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + PurchaseOrder order = new PurchaseOrder(); + order.setName(reader.getAttribute("name")); + order.setPrice(Double.parseDouble(reader.getAttribute("price"))); + order.setAmount(Double.parseDouble(reader.getAttribute("amount"))); + return order; + } + + public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) { + + writer.addAttribute("name", ((PurchaseOrder)object).getName()); + writer.addAttribute("price", Double.toString(((PurchaseOrder) object).getPrice())); + writer.addAttribute("amount", Double.toString(((PurchaseOrder) object).getAmount())); + } + } +} \ No newline at end of file Added: camel/trunk/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml?rev=961922&view=auto ============================================================================== --- camel/trunk/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml (added) +++ camel/trunk/components/camel-xstream/src/test/resources/org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml Thu Jul 8 20:35:28 2010 @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <bean id="xs1" class="org.apache.camel.dataformat.xstream.XStreamDataFormat" /> + + <!-- START SNIPPET: e1 --> + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + + <!-- we define the json xstream data formats to be used (xstream is default) --> + <dataFormats> + <xstream id="xstream-1"> + <converters> + <converter class="org.apache.camel.dataformat.xstream.XStreamConfigurationTest$PurchaseOrderConverter" /> + </converters> + <aliases> + <alias name="purchase-order" class="org.apache.camel.dataformat.xstream.PurchaseOrder" /> + </aliases> + <implicitCollections> + <class name="org.apache.camel.dataformat.xstream.PurchaseHistory"> + <field>history</field> + </class> + </implicitCollections> + </xstream> + + <xstream id="xstream-json" driver="json"> + <converters> + <converter class="org.apache.camel.dataformat.xstream.XStreamConfigurationTest$PurchaseOrderConverter" /> + </converters> + <aliases> + <alias name="purchase-order" class="org.apache.camel.dataformat.xstream.PurchaseOrder" /> + </aliases> + <implicitCollections> + <class name="org.apache.camel.dataformat.xstream.PurchaseHistory"> + <field>history</field> + </class> + </implicitCollections> + </xstream> + </dataFormats> + + <route> + <from uri="direct:marshal"/> + <marshal ref="xstream-1" /> + <to uri="mock:result"/> + </route> + + <route> + <from uri="direct:unmarshal"/> + <unmarshal ref="xstream-1"/> + <to uri="mock:result"/> + </route> + + <route> + <from uri="direct:marshal-json"/> + <marshal ref="xstream-json" /> + <to uri="mock:result"/> + </route> + + <route> + <from uri="direct:unmarshal-json"/> + <unmarshal ref="xstream-json"/> + <to uri="mock:result"/> + </route> + + </camelContext> + +</beans>