开发者

unmarshalling complex types with Jaxb2

开发者 https://www.devze.com 2023-04-08 14:36 出处:网络
Hi I have following XML and java classes when I unmarshall using JAXB2 processor using Spring OXM framework I am getting all null values. Any idea?

Hi I have following XML and java classes when I unmarshall using JAXB2 processor using Spring OXM framework I am getting all null values. Any idea?

import javax.xml.bind.annotation.开发者_运维技巧XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="AuthentXML",namespace="http://xml.authentify.net/MessageSchema.xml")
public class AuthentifyResult { 
    private Header header;
    public Header getHeader() {
        return header;
    }
    public void setHeader(Header header) {
        this.header = header;
    }
}

@XmlType(name="", propOrder={"asid", "teid", "replyTo"}) 
public class Header {
 private String asid;

private String teid;

private String replyTo;
public String getAsid() {
 return asid;
}
public void setAsid(String asid) {
this.asid = asid;
}
public String getTeid() {
return teid;
}
public void setTeid(String teid) {
this.teid = teid;
}
public String getReplyTo() {
return replyTo;
}
public void setReplyTo(String replyTo) {
this.replyTo = replyTo;
}
}

<?xml version="1.0" ?>
<AuthentXML>
<header>
<asid>AuthenticationSubjectID</asid>
<teid>B6F997AE-FB4E-11D3-80BD-0050DA5DC7B8</teid>
<replyTo>https://r1.authentify.net/s2s/default.asp</replyTo>
</header>
</AuthentXML>

unmarshaling code

FileInputStream is = null;

is = new FileInputStream(FILE_NAME);
this.authentifyResult = (AuthentifyResult) this.jaxbUnmarshaller.unmarshal(new StreamSource(is));

I am receiving null for header in authentifyResult. Why?


The only thing I see wrong with your code is that the @XmlRootElement annotation on AuthentifyResult should not specify a namespace since the XML fragment you posted is not namespace qualified:

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="AuthentXML")
public class AuthentifyResult { 
    private Header header;
    public Header getHeader() {
        return header;
    }
    public void setHeader(Header header) {
        this.header = header;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号