camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Ravindra.Godb...@cognizant.com>
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);

                        @Override
                        public void configure() throws Exception {
                                from("direct:start").
                                unmarshal(jaxbFormat).
                                log("Received ${body}"); // You can redirect to file if you
want.
                        }
                };
        }

// Populate the route with orders.

        @Test
        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"));

                cdb.setOrder(orders);

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

        }


// Orders class

@XmlRootElement
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

@XmlRootElement
public class Order {

        String name;
        int age;
        int id;
......


Hope this helps.



-Ravi




-----Original Message-----
From: contactreji [mailto:contactreji@gmail.com]
Sent: Friday, April 18, 2014 7:31 AM
To: users@camel.apache.org
Subject: Camel JAXB - ArrayList of Objects to XML

Hi

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

<Orders>
      <Order>
         ..........
         ..........
       </Order>

       <Order>
          ..........
          ..........
      </Order>

</Orders>






--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JAXB-ArrayList-of-Objects-to-XML-tp5750356.html
Sent from the Camel - Users mailing list archive at Nabble.com.
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.

Mime
View raw message