与 Web 服务响应中返回的列表的 Jaxb 绑定
Jaxb Binding with List returned in web service response
我正在开发一个 jax-ws 客户端,我正在尝试处理作为响应返回的 ArrayList,但我的列表始终为空。
返回的列表不为空,我确定 WebService 提供程序正在返回该列表中的数据,我使用 SoapUI 进行了检查。
生成客户端相关文件:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfFact", propOrder = {
"item"
})
public class ArrayOfFact {
protected List<Fact> item;
public List<Fact> getItem() {
if (item == null) {
item = new ArrayList<Fact>();
}
return this.item;
}
}
ArrayOfFacts class 由 wsimport 生成,与之前生成的 class 相同。
我在 SOAPUI 中收到的 XML 响应:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ReleveResponse xmlns="http://www.test.ma/webservices/WSTestServe/">
<ReleveResult>
<ConversationId>conId</ConversationId>
<Status>
<WSStatus>OK</WSStatus>
<WSCode>OK</WSCode>
<WSMessage>Le traitement s’est bien déroulé!</WSMessage>
</Status>
<myReleveInfo>
<NomCli>El Karkouri youssef</NomCli>
<NbrImp>7</NbrImp>
<Facture>
<Fact>
<RefImp>FACT-124</RefImp>
<MntImp>230</MntImp>
<LibImp>label 1</LibImp>
<FlgPaiObl>1</FlgPaiObl>
</Fact>
<Fact>
<RefImp>FACT-125</RefImp>
<MntImp>260</MntImp>
<LibImp>label 0</LibImp>
<FlgPaiObl>0</FlgPaiObl>
</Fact>
<Fact>
<RefImp>FACT-126</RefImp>
<MntImp>360</MntImp>
<LibImp>label 2</LibImp>
<FlgPaiObl>0</FlgPaiObl>
</Fact>
<Fact>
<RefImp>FACT-127</RefImp>
<MntImp>236</MntImp>
<LibImp>label 3</LibImp>
<FlgPaiObl>0</FlgPaiObl>
</Fact>
<Fact>
<RefImp>FACT-128</RefImp>
<MntImp>2310</MntImp>
<LibImp>label 4</LibImp>
<FlgPaiObl>1</FlgPaiObl>
</Fact>
<Fact>
<RefImp>FACT-129</RefImp>
<MntImp>2450</MntImp>
<LibImp>label 0</LibImp>
<FlgPaiObl>1</FlgPaiObl>
</Fact>
<Fact>
<RefImp>FACT-167</RefImp>
<MntImp>2380</MntImp>
<LibImp>label 1125</LibImp>
<FlgPaiObl>0</FlgPaiObl>
</Fact>
</Facture>
</myReleveInfo>
</ReleveResult>
</ReleveResponse>
</soapenv:Body>
</soapenv:Envelope>
我在测试 jax-ws 客户端时收到的 JSON 响应:
{
"status": "OK",
"language": "en",
"data": {
"conversationId": {
"name": "{http://www.test.ma/webservices/WSTestServe/}ConversationId",
"declaredType": "java.lang.String",
"scope": "ma.comp.company.client.testserv.AbstractBean",
"value": "conId",
"nil": false,
"globalScope": false,
"typeSubstituted": false
},
"status": {
"name": "{http://www.test.ma/webservices/WSTestServe/}Status",
"declaredType": "ma.comp.company.client.testserv.StatusBeanOut",
"scope": "ma.comp.company.client.testserv.AbstractBeanOutOfReleveInfo",
"value": {
"wsstatus": "OK",
"wscode": "OK",
"wsmessage": "Le traitement s’est bien déroulé!"
},
"nil": false,
"globalScope": false,
"typeSubstituted": false
},
"myReleveInfo": {
"nomCli": {
"name": "{http://www.test.ma/webservices/WSTestServe/}NomCli",
"declaredType": "java.lang.String",
"scope": "ma.comp.company.client.testserv.ReleveInfo",
"value": "El Karkouri youssef",
"nil": false,
"globalScope": false,
"typeSubstituted": false
},
"nbrImp": {
"name": "{http://www.test.ma/webservices/WSTestServe/}NbrImp",
"declaredType": "java.lang.String",
"scope": "ma.comp.company.client.testserv.ReleveInfo",
"value": "7",
"nil": false,
"globalScope": false,
"typeSubstituted": false
},
"facture": {
"name": "{http://www.test.ma/webservices/WSTestServe/}Facture",
"declaredType": "ma.comp.company.client.testserv.ArrayOfFact",
"scope": "ma.comp.company.client.testserv.ReleveInfo",
"value": {
"item": []
},
"nil": false,
"globalScope": false,
"typeSubstituted": false
}
}
},
"message": null
}
事实class:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Fact", propOrder = {
"refImp",
"mntImp",
"libImp",
"flgPaiObl"
})
public class Fact {
@XmlElementRef(name = "RefImp", namespace = "http://www.test.ma/webservices/WSTesServe/", type = JAXBElement.class, required = false)
protected JAXBElement<String> refImp;
@XmlElementRef(name = "MntImp", namespace = "http://www.test.ma/webservices/WSTesServe/", type = JAXBElement.class, required = false)
protected JAXBElement<String> mntImp;
@XmlElementRef(name = "LibImp", namespace = "http://www.test.ma/webservices/WSTesServe/", type = JAXBElement.class, required = false)
protected JAXBElement<String> libImp;
@XmlElementRef(name = "FlgPaiObl", namespace = "http://www.test.ma/webservices/WSTesServe/", type = JAXBElement.class, required = false)
protected JAXBElement<String> flgPaiObl;
// Getters and Setters
}
我通过在 wsimport
生成的 class ObjectFactory 中添加一个 xml 元素声明来解决这个问题
@XmlElementDecl(namespace = "http://www.test.ma/webservices/WSTestServe/", name = "Fact", scope = ArrayOfFact.class)
public JAXBElement<Fact> createArrayOfFactItem(Fact value) {
return new JAXBElement<Fact>(_ReleveInfoFact_QNAME, Fact.class, ArrayOfFact.class, value);
}
项目列表应注释为:
@XmlElementRef(name = "Fact", namespace = "http://www.test.ma/webservices/WSTestServe/", type = JAXBElement.class, required = false)
protected List<Fact> item;
我正在开发一个 jax-ws 客户端,我正在尝试处理作为响应返回的 ArrayList,但我的列表始终为空。
返回的列表不为空,我确定 WebService 提供程序正在返回该列表中的数据,我使用 SoapUI 进行了检查。
生成客户端相关文件:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfFact", propOrder = {
"item"
})
public class ArrayOfFact {
protected List<Fact> item;
public List<Fact> getItem() {
if (item == null) {
item = new ArrayList<Fact>();
}
return this.item;
}
}
ArrayOfFacts class 由 wsimport 生成,与之前生成的 class 相同。
我在 SOAPUI 中收到的 XML 响应:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ReleveResponse xmlns="http://www.test.ma/webservices/WSTestServe/">
<ReleveResult>
<ConversationId>conId</ConversationId>
<Status>
<WSStatus>OK</WSStatus>
<WSCode>OK</WSCode>
<WSMessage>Le traitement s’est bien déroulé!</WSMessage>
</Status>
<myReleveInfo>
<NomCli>El Karkouri youssef</NomCli>
<NbrImp>7</NbrImp>
<Facture>
<Fact>
<RefImp>FACT-124</RefImp>
<MntImp>230</MntImp>
<LibImp>label 1</LibImp>
<FlgPaiObl>1</FlgPaiObl>
</Fact>
<Fact>
<RefImp>FACT-125</RefImp>
<MntImp>260</MntImp>
<LibImp>label 0</LibImp>
<FlgPaiObl>0</FlgPaiObl>
</Fact>
<Fact>
<RefImp>FACT-126</RefImp>
<MntImp>360</MntImp>
<LibImp>label 2</LibImp>
<FlgPaiObl>0</FlgPaiObl>
</Fact>
<Fact>
<RefImp>FACT-127</RefImp>
<MntImp>236</MntImp>
<LibImp>label 3</LibImp>
<FlgPaiObl>0</FlgPaiObl>
</Fact>
<Fact>
<RefImp>FACT-128</RefImp>
<MntImp>2310</MntImp>
<LibImp>label 4</LibImp>
<FlgPaiObl>1</FlgPaiObl>
</Fact>
<Fact>
<RefImp>FACT-129</RefImp>
<MntImp>2450</MntImp>
<LibImp>label 0</LibImp>
<FlgPaiObl>1</FlgPaiObl>
</Fact>
<Fact>
<RefImp>FACT-167</RefImp>
<MntImp>2380</MntImp>
<LibImp>label 1125</LibImp>
<FlgPaiObl>0</FlgPaiObl>
</Fact>
</Facture>
</myReleveInfo>
</ReleveResult>
</ReleveResponse>
</soapenv:Body>
</soapenv:Envelope>
我在测试 jax-ws 客户端时收到的 JSON 响应:
{
"status": "OK",
"language": "en",
"data": {
"conversationId": {
"name": "{http://www.test.ma/webservices/WSTestServe/}ConversationId",
"declaredType": "java.lang.String",
"scope": "ma.comp.company.client.testserv.AbstractBean",
"value": "conId",
"nil": false,
"globalScope": false,
"typeSubstituted": false
},
"status": {
"name": "{http://www.test.ma/webservices/WSTestServe/}Status",
"declaredType": "ma.comp.company.client.testserv.StatusBeanOut",
"scope": "ma.comp.company.client.testserv.AbstractBeanOutOfReleveInfo",
"value": {
"wsstatus": "OK",
"wscode": "OK",
"wsmessage": "Le traitement s’est bien déroulé!"
},
"nil": false,
"globalScope": false,
"typeSubstituted": false
},
"myReleveInfo": {
"nomCli": {
"name": "{http://www.test.ma/webservices/WSTestServe/}NomCli",
"declaredType": "java.lang.String",
"scope": "ma.comp.company.client.testserv.ReleveInfo",
"value": "El Karkouri youssef",
"nil": false,
"globalScope": false,
"typeSubstituted": false
},
"nbrImp": {
"name": "{http://www.test.ma/webservices/WSTestServe/}NbrImp",
"declaredType": "java.lang.String",
"scope": "ma.comp.company.client.testserv.ReleveInfo",
"value": "7",
"nil": false,
"globalScope": false,
"typeSubstituted": false
},
"facture": {
"name": "{http://www.test.ma/webservices/WSTestServe/}Facture",
"declaredType": "ma.comp.company.client.testserv.ArrayOfFact",
"scope": "ma.comp.company.client.testserv.ReleveInfo",
"value": {
"item": []
},
"nil": false,
"globalScope": false,
"typeSubstituted": false
}
}
},
"message": null
}
事实class:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Fact", propOrder = {
"refImp",
"mntImp",
"libImp",
"flgPaiObl"
})
public class Fact {
@XmlElementRef(name = "RefImp", namespace = "http://www.test.ma/webservices/WSTesServe/", type = JAXBElement.class, required = false)
protected JAXBElement<String> refImp;
@XmlElementRef(name = "MntImp", namespace = "http://www.test.ma/webservices/WSTesServe/", type = JAXBElement.class, required = false)
protected JAXBElement<String> mntImp;
@XmlElementRef(name = "LibImp", namespace = "http://www.test.ma/webservices/WSTesServe/", type = JAXBElement.class, required = false)
protected JAXBElement<String> libImp;
@XmlElementRef(name = "FlgPaiObl", namespace = "http://www.test.ma/webservices/WSTesServe/", type = JAXBElement.class, required = false)
protected JAXBElement<String> flgPaiObl;
// Getters and Setters
}
我通过在 wsimport
生成的 class ObjectFactory 中添加一个 xml 元素声明来解决这个问题@XmlElementDecl(namespace = "http://www.test.ma/webservices/WSTestServe/", name = "Fact", scope = ArrayOfFact.class)
public JAXBElement<Fact> createArrayOfFactItem(Fact value) {
return new JAXBElement<Fact>(_ReleveInfoFact_QNAME, Fact.class, ArrayOfFact.class, value);
}
项目列表应注释为:
@XmlElementRef(name = "Fact", namespace = "http://www.test.ma/webservices/WSTestServe/", type = JAXBElement.class, required = false)
protected List<Fact> item;