camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem jiang <willem.ji...@gmail.com>
Subject Re: JAXB partial unmarshalling
Date Mon, 16 Sep 2013 08:46:33 GMT
The Partial unmarshalling just works for the element start with <MobilePhone>.
You have to skip the <Result> part yourself.


--  
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 Monday, September 16, 2013 at 12:40 PM, hutao722 wrote:

> 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 (http://Nabble.com).




Mime
View raw message