Hi, 

I tried to do JAXB partial unmarshalling test, but always get null values
from xml to java object. The code like this:

JaxbDataFormat jaxb = new JaxbDataFormat(false);
jaxb.setContextPath("org.apache.camel.example.server.model6");
jaxb.setPartClass("org.apache.camel.example.server.model6.MobilePhone");
from("direct:example")
.process(new Processor() {
    @Override
     public void process(Exchange exchange) throws Exception {
         StringBuffer sb = new StringBuffer();
         sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
         sb.append("<Result
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\";
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"; xmlns=\"Yangzhili\">");
         sb.append("<MobilePhone>");
         sb.append("<QueryResult>success</QueryResult>"); 
         sb.append("<AreaCode>100000</AreaCode>");
         sb.append("</MobilePhone>");
         sb.append("</Result>");
         exchange.getIn().setBody(sb.toString());
         }
})
.unmarshal(jaxb)
.process(new Processor() {
    @Override
    public void process(Exchange exchange) throws Exception {
          MobilePhone sq = exchange.getIn().getBody(MobilePhone.class);
          if (sq.getQueryResult() != null)
        System.out.println("result is : " + sq.toString());
          }
});

The class of MobilePhone:
@XmlRootElement(name="MobilePhone")
@XmlAccessorType(XmlAccessType.FIELD)
public class MobilePhone {
        @XmlElement
        private String QueryResult;
        @XmlElement
        private String AreaCode;
}

The values of QueryResult & AreaCode are always null. Why? Do i have some
wrong?



--
View this message in context: 
http://camel.465427.n5.nabble.com/JAXB-partial-unmarshalling-tp5739497.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to