2011-09-23 87 views
1

您好我有下面的XML和Java類,當我使用JAXB2處理器使用Spring OXM框架解組我收到所有空值。任何想法?解組複雜類型與Jaxb2

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)); 

我在authentifyResult中收到標頭的空值。爲什麼?

回答

2

我看到你的代碼錯誤的唯一的事情是,@XmlRootElement註釋上AuthentifyResult不應該,因爲您發佈的XML片段指定一個名字空間不是名稱空間限定:

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; 
    } 
}