我需要使用jaxb取消对java对象的嵌套soap响应。但我总是得到一个空指针异常。
我已经检查了几乎所有链接,如下所示: jaxb unmarshalling returns null jaxb unmarshalling giving NULL to anytype element in xsd
但没有任何事情可以帮助我。
这是我的肥皂回应消息
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsap.org/sap/env/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<soapenv:Body>
<ns1:subscribeProductResponse xmlns:ns1='http://www.csapi.org/schema/parlayx/subscribe/manage/v1_0/local'>
<ns1:subscribeProductRsp>
<result>22007233</result>
<resultDescription>Temporary Order saved successfully! DataSendStep finish end.</resultDescription>
</ns1:subscribeProductRsp>
</ns1:subscribeProductResponse>
</soapenv:Body>
</soapenv:Envelope>
以下是我的Java Pojo类
@XmlRootElement (name="subscribeProductResponse",namespace="http://www.csapi.org/schema/parlayx/subscribe/manage/v1_0/local")
@XmlAccessorType(XmlAccessType.FIELD)
public class SubscribeProductResponse {
// @XmlElementWrapper
@XmlElement(name="subscribeProductRsp")
private SubscribeProductRsp subscribeProductRsp;
public SubscribeProductRsp getSubscribeProductRsp() {
return subscribeProductRsp;
}
public void setSubscribeProductRsp(SubscribeProductRsp subscribeProductRsp) {
this.subscribeProductRsp = subscribeProductRsp;
}
}
@XmlRootElement(name="subscribeProductRsp")
public class SubscribeProductRsp {
private String result;
private String resultDescription;
public String getResult() {
return result;
}
@XmlElement(name = "result", required = true)
public void setResult(String result) {
this.result = result;
}
public String getResultDescription() {
return resultDescription;
}
@XmlElement(name = "resultDescription", required = true)
public void setResultDescription(String resultDescription) {
this.resultDescription = resultDescription;
}
@Override
public String toString() {
return "ClassPojo [result = " + result + ", resultDescription = "
+ resultDescription + "]";
}
}
以下是解组响应消息的代码
JAXBContext jc = JAXBContext.newInstance(SubscribeProductResponse.class);
Unmarshaller um = jc.createUnmarshaller();
SubscribeProductResponse output = (SubscribeProductResponse)um.unmarshal(soapResponse.getSOAPBody().extractContentAsDocument());
System.out.println(output.getSubscribeProductRsp().getResult());
JAXBContext jc = JAXBContext.newInstance(SubscribeProductResponse.class);
Unmarshaller um = jc.createUnmarshaller();
SubscribeProductResponse output = (SubscribeProductResponse)um.unmarshal(soapResponse.getSOAPBody().extractContentAsDocument());
System.out.println(output.getSubscribeProductRsp().getResult());
我将output.getSubscribeProductRsp()视为null
任何人都可以告诉我我做错了什么。