Java JAXB复杂XML反序列化(解组)
我正在尝试将xml数据反序列化为Java对象。它已反序列化,但子项列表为空,即数组为空。我尝试了不同的方法,但失败了 输入xml字符串Java JAXB复杂XML反序列化(解组),java,xml,jaxb,unmarshalling,Java,Xml,Jaxb,Unmarshalling,我正在尝试将xml数据反序列化为Java对象。它已反序列化,但子项列表为空,即数组为空。我尝试了不同的方法,但失败了 输入xml字符串 String tempXML = "<searchbadge xmlns=\"www.Ingo.com/Api/v1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance \"><errorcode>0</errorcode><errormessage/
String tempXML = "<searchbadge xmlns=\"www.Ingo.com/Api/v1.0\"
xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance
\"><errorcode>0</errorcode><errormessage/><matches><match><address>road
A</address><badgeno>10109</badgeno><bday>7/13/2015 12:00:00 AM</bday>
<city>Roswell</city><name>Jason Reed</name><phone>876 456 2345</phone>
<state>Georgia</state><zip>30320</zip></match></matches></searchbadge>";
解组码
public static SearchBadgeResponse getObjectTmp(String valXML) {
SearchBadgeResponse myobj = null;
try
{
JAXBContext jaxbContextDes =
JAXBContext.newInstance(SearchBadgeResponse.class);
Unmarshaller unmarshaller = jaxbContextDes.createUnmarshaller();
StringReader reader = new StringReader(valXML);
myobj = (SearchBadgeResponse) unmarshaller.unmarshal(reader);
return myobj;
}
catch(JAXBException jex)
{
jex.printStackTrace();
}
return myobj;
}
我想不出这个问题。任何提示/示例都很明显。将名称空间属性添加到子类:
@XmlRootElement(name = "match", namespace="www.Ingo.com/Api/v1.0")
public class Match implements Serializable{
public static SearchBadgeResponse getObjectTmp(String valXML) {
SearchBadgeResponse myobj = null;
try
{
JAXBContext jaxbContextDes =
JAXBContext.newInstance(SearchBadgeResponse.class);
Unmarshaller unmarshaller = jaxbContextDes.createUnmarshaller();
StringReader reader = new StringReader(valXML);
myobj = (SearchBadgeResponse) unmarshaller.unmarshal(reader);
return myobj;
}
catch(JAXBException jex)
{
jex.printStackTrace();
}
return myobj;
}
@XmlRootElement(name = "match", namespace="www.Ingo.com/Api/v1.0")
public class Match implements Serializable{