Hi,

I just ran an unit test to verify the DSL, it works out of box.
But I just want to ask if you have ObjectFactory in the package of PurchaseOrder
  to let the JAXB know the namespace mapping.


--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) 
(English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem




On Tuesday, November 12, 2013 at 5:04 PM, kakashi wrote:

> I was able to marshal java object to Xml file successfully.
> But not able to unmarshal Xml file to java object back.
> My purchase order class:
> import javax.xml.bind.annotation.XmlAccessType;
> import javax.xml.bind.annotation.XmlAccessorType;
> import javax.xml.bind.annotation.XmlAttribute;
> import javax.xml.bind.annotation.XmlElement;
> import javax.xml.bind.annotation.XmlRootElement;
>  
> @XmlRootElement
> @XmlAccessorType(XmlAccessType.FIELD)
> public class PurchaseOrder {
> @XmlAttribute
> private String name;
>  
> public String getName() {
> return name;
> }
>  
> public void setName(String name) {
> this.name (http://this.name) = name;
> }
>  
> public double getPrice() {
> return price;
> }
>  
> public void setPrice(double price) {
> this.price = price;
> }
>  
> public double getAmount() {
> return amount;
> }
>  
> public void setAmount(double amount) {
> this.amount = amount;
> }
>  
> @XmlAttribute
> private double price;
>  
> @XmlAttribute
> private double amount;
>  
> }
>  
>  
>  
> My unmarshaller code is as follows :
>  
> import javax.jms.ConnectionFactory;
> import javax.xml.bind.JAXBContext;
>  
> import java.io.File;
> import java.math.BigDecimal;
> import java.util.Dictionary;
> import java.util.HashMap;
> import java.util.Map;
>  
> import org.apache.activemq.ActiveMQConnectionFactory;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Exchange;
> import org.apache.camel.Processor;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.jms.JmsComponent;
> import org.apache.camel.dataformat.bindy.kvp.BindyKeyValuePairDataFormat;
> import org.apache.camel.impl.DefaultCamelContext;
> import org.apache.camel.model.dataformat.BindyDataFormat;
> import org.apache.camel.model.dataformat.BindyType;
> import org.apache.camel.model.dataformat.CastorDataFormat;
> import org.apache.camel.model.dataformat.JaxbDataFormat;
> import org.apache.camel.spi.DataFormat;
>  
>  
> public class JaxbTestUnmarshal
> {
> public static void main(String[] args) throws Exception {
> CamelContext context = new DefaultCamelContext();  
> context.addRoutes(new RouteBuilder() {
> public void configure() {
> // JaxbDataFormat jaxbUnmarshal = new JaxbDataFormat();
> //  
> jaxbUnmarshal.setContextPath(PurchaseOrder.class.getPackage().getName().toString());
>  
> from("file://test2?fileName=jaxb.xml").unmarshal().jaxb(PurchaseOrder.class.getPackage().getName().toString()).process(new
> Processor() {
>  
> @Override
> public void process(Exchange exchange) throws Exception {
> PurchaseOrder porder =(PurchaseOrder) exchange.getIn().getBody();
> System.out.println("Name is :"+porder.getName());
>  
> }
> });
> }
> });
>  
> context.start();
> Thread.sleep(1000);
> context.stop();
>  
> }
>  
> }
>  
> Here is my xml:
>  
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <purchaseOrder amount="45.0" price="45.0" name="kakashi"/>
>  
>  
> i tried t debug the code .its not entering the process block.
> Thanks in advance.
>  
>  
>  
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Unmarshalling-using-Jaxb-to-POJO-tp5743079.html
> Sent from the Camel - Users mailing list archive at Nabble.com 
> (http://Nabble.com).



Reply via email to