camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject RE: Camel JAXB - ArrayList of Objects to XML
Date Fri, 18 Apr 2014 06:25:11 GMT
You can definitely do it.

Create route like this :

        protected RouteBuilder createRouteBuilder() throws Exception {
                return new RouteBuilder() {

                        JAXBContext context = JAXBContext.newInstance(new Class[]{Orders.class});
                        Unmarshaller um = context.createUnmarshaller();

                        JaxbDataFormat jaxbFormat = new JaxbDataFormat(context);

                        public void configure() throws Exception {
                                log("Received ${body}"); // You can redirect to file if you

// Populate the route with orders.

        public void testJaxBContents() throws Exception {

                Orders cdb = new Orders();

                List<Order> orders = new ArrayList<Order>();
                orders.add(new Order(1, 21, "oine"));
                orders.add(new Order(2, 22, "two"));
                orders.add(new Order(3, 23, "three"));


                template.sendBody("direct:start", cdb);


// Orders class

public class Orders {

        List<Order> order = new ArrayList<Order>();

        public List<Order> getOrder() {
                return order;

        public void setOrder(List<Order> records) {
                this.order = records;

// Order class

public class Order {

        String name;
        int age;
        int id;

Hope this helps.


-----Original Message-----
From: contactreji []
Sent: Friday, April 18, 2014 7:31 AM
Subject: Camel JAXB - ArrayList of Objects to XML


Is there a way to convert incoming ArrayList of Java Objects into XML?

I have used camel JAXB component for converting a simple object into XML.
But according to my requirement, I need to create an XML file containing multiple Order details
into a XML containing a root tag as Orders and sub tags as Order

Something link




View this message in context:
Sent from the Camel - Users mailing list archive at
This e-mail and any files transmitted with it are for the sole use of the intended recipient(s)
and may contain confidential and privileged information. If you are not the intended recipient(s),
please reply to the sender and destroy all copies of the original message. Any unauthorized
review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or
any action taken in reliance on the contents of this e-mail is strictly prohibited and may
be unlawful.

View raw message