2
元素我收到的XML看起來像:JAXB:Unmarshaller的找不到命名空間和前綴
<result xmlns="firstUri">
<blackList xmlns:ns1="secondUri">
<ns2:BlackList xmlns:ns2="thirdUri">
<name xmlns="thirdUri">some value</name>
<nameFlag xmlns="thirdUri">some value</nameFlag>
</ns2:BlackList>
<ns2:BlackList xmlns:ns2="thirdUri">
<name xmlns="thirdUri">some value</name>
<nameFlag xmlns="thirdUri">some value</nameFlag>
</ns2:BlackList>
..........................................................
</blackList>
<retCode xmlns:ns1="secondUri">0</retCode>
<retDesc xmlns:ns1="secondUri">Succeeded</retDesc>
</result>
我想解組它的對象。
我創建了以下豆:
@XmlRootElement(name = "result", namespace ="firstUri")
public class GetBlackListResp {
protected String retCode;
protected String retDesc;
protected List<BlackListItem> blackListArray;
@XmlRootElement(name = "BlackList", namespace = "thirdUri")
public static class BlackListItem{
protected String name;
protected String nameFlag;
@XmlElement(name = "name", namespace = "thirdUri")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElement(name = "nameFlag", namespace = "thirdUri")
public String getNameFlag() {
return nameFlag;
}
public void setNameFlag(String nameFlag) {
this.nameFlag = nameFlag;
}
}
@XmlElement(name = "retCode", namespace = "firstUri")
public String getRetCode() {
return retCode;
}
public void setRetCode(String retCode) {
this.retCode = retCode;
}
@XmlElement(name = "retDesc", namespace = "firstUri")
public String getRetDesc() {
return retDesc;
}
public void setRetDesc(String retDesc) {
this.retDesc = retDesc;
}
@XmlElement(name = "blackList", namespace = "firstUri")
public List<BlackListItem> getBlackList() {
return blackListArray;
}
public void setBlackList(List<BlackListItem> blackListArray) {
this.blackListArray = blackListArray;
}
}
解組我有對象,這是成功的填補,除了blackListArray場之後。該字段包含只有一個項目的列表。該項目中的所有領域都是空值。
看起來JAXB可以找到元素,但想念裏面的所有內部元素。
我使用MOXy作爲JAXB實現。
P.S.
我試圖把package-info.java的文件夾我的豆爲that question
@XmlSchema(
elementFormDefault=XmlNsForm.QUALIFIED,
namespace="thirdUri",
xmlns={@XmlNs(prefix="ns2",
namespaceURI="thirdUri")}
)
package package.with.my.bean;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;
說,但它並沒有幫助我。
非常感謝!改變之後,所有工作都很好=) – Sergey