我目前正面临实体和WSDL定义之间的wsdl错配。它似乎忽略了复杂类型的列表。我使用Axis 2从XSD文件生成的实体生成WSDL。
以下是XSD文件的一部分:
<xs:element name="Funds">
<xs:complexType>
<xs:sequence>
<xs:element name="Fund" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="code" />
<xs:element type="xs:string" name="Status" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
这将生成以下实体:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"fund"
})
public static class Funds {
@XmlElement(name = "Fund")
@XmlAnyElement(lax=true)
protected List<Request.Funds.Fund> fund;
public List<Request.Funds.Fund> getFund() {
if (fund == null) {
fund = new ArrayList<Request.Funds.Fund>();
}
return this.fund;
}
public void setFund(List<Request.Funds.Fund> fund) {
this.fund = fund;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"code",
"status"
})
public static class Fund {
@XmlElement(name = "CODE", required = true)
protected String code;
@XmlElement(name = "Status", required = true)
protected String status;
public String getCODE() {
return code;
}
public void setCODE(String value) {
this.code = value;
}
public String getStatus() {
return status;
}
public void setStatus(String value) {
this.status = value;
}
}
}
这个生成的代码提供了以下WSDL:
<xs:complexType name="Request_Funds">
<xs:sequence>
<xs:element minOccurs="0" name="fund" nillable="true" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
列表的类型为anyType,所以当它被解组时我会收到以下错误:
java.lang.ClassCastException: org.apache.axiom.om.impl.llom.OMElementImpl cannot be cast to com.legalsuite.services.start.importxml.Request$Funds$Fund
我该怎么做才能避免这种行为?
答案 0 :(得分:0)
由于您没有将Funds
声明为XmlElement
,因此它不是您的WSDL的一部分。它只是一个容器。
我认为你应该明确声明Funds
所以WSDL没有混淆如下:
@XmlElement(name = "Funds")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"Fund"
})
public static class Funds {
@XmlElement(name = "Fund")
@XmlAnyElement(lax=true)
protected List<Request.Funds.Fund> fund;
public List<Request.Funds.Fund> getFund() {
if (fund == null) {
fund = new ArrayList<Request.Funds.Fund>();
}
return this.fund;
}
public void setFund(List<Request.Funds.Fund> fund) {
this.fund = fund;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"code",
"status"
})
public static class Fund {
@XmlElement(name = "CODE", required = true)
protected String code;
@XmlElement(name = "Status", required = true)
protected String status;
public String getCODE() {
return code;
}
public void setCODE(String value) {
this.code = value;
}
public String getStatus() {
return status;
}
public void setStatus(String value) {
this.status = value;
}
}
}