首页 > 解决方案 > SOAP Response with array not cast to typed object (get elementNSImpl)如何解决这个问题?

问题描述

我在将肥皂响应转换为定义类型(类)时遇到问题。

所有人都在使用另一个模型,但在这个肥皂调用中,我得到了包含对象数组(invoice_details)的响应,在这个调用中我得到了 elementNSimpl。

这是 SOAP UI 响应:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.sugarcrm.com/sugarcrm">
   <SOAP-ENV:Body>
      <ns1:get_invoice_listResponse xmlns:ns1="http://www.sugarcrm.com/sugarcrm">
         <return xsi:type="tns:invoice_list_cus_info">
            <customer_info xsi:type="tns:customer_info">
               <customer_name xsi:type="xsd:string">Тест Тест</customer_name>
            </customer_info>
            <invoice_list xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:invoice_details[1]">
               <item xsi:type="tns:invoice_details">
                  <month xsi:type="xsd:string">xxxxxxxxxxxx</month>
                  <invoice_number xsi:type="xsd:string">xxxxxxxxxxxxxx</invoice_number>
                  <amount xsi:type="xsd:string">xxxxxxxxxxxxxxxx</amount>
               </item>
            </invoice_list>
            <status_message xsi:type="xsd:string">Success</status_message>
         </return>
      </ns1:get_invoice_listResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这个类是用 maven-jaxb2-plugin 生成的。

这是生成的类:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
        "_return"
})
@XmlRootElement(name = "get_invoice_listResponse")
public class GetInvoiceListResponse {

    @XmlElement(name = "return", required = true, nillable = true)
    protected InvoiceListCusInfo _return;

    /**
     * Gets the value of the return property.
     *
     * @return possible object is
     * {@link InvoiceListCusInfo }
     */
    public InvoiceListCusInfo getReturn() {
        return _return;
    }

    /**
     * Sets the value of the return property.
     *
     * @param value allowed object is
     *              {@link InvoiceListCusInfo }
     */
    public void setReturn(InvoiceListCusInfo value) {
        this._return = value;
    }

}

这是 InvoiceListCusInfo.class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "invoice_list_cus_info", propOrder = {

})
public class InvoiceListCusInfo {

    @XmlElement(name = "customer_info", required = true)
    protected CustomerInfo customerInfo;
    @XmlElement(name = "invoice_list", required = true)
    protected InvoiceList invoiceList;
    @XmlElement(name = "total_amount", required = true)
    protected java.lang.String totalAmount;
    @XmlElement(name = "status_message", required = true)
    protected java.lang.String statusMessage;

    getter/setter

}

这是 InvoiceList.class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "invoice_list")
public class InvoiceList
    extends Array
{


}

这是 Array.class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Array", namespace = "http://schemas.xmlsoap.org/soap/encoding/", propOrder = {
    "any"
})
@XmlSeeAlso({
    InvoiceList.class
})
public class Array {

    @XmlAnyElement(lax = true)
    protected List<Object> any;
    @XmlAttribute(name = "arrayType", namespace = "http://schemas.xmlsoap.org/soap/encoding/")
    protected java.lang.String arrayType;
    @XmlAttribute(name = "offset", namespace = "http://schemas.xmlsoap.org/soap/encoding/")
    protected java.lang.String offset;
    @XmlAttribute(name = "id")
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    @XmlID
    @XmlSchemaType(name = "ID")
    protected java.lang.String id;
    @XmlAttribute(name = "href")
    @XmlSchemaType(name = "anyURI")
    protected java.lang.String href;
    @XmlAnyAttribute
    private Map<QName, java.lang.String> otherAttributes = new HashMap<QName, java.lang.String>();

我得到这个回应:

    {
        "customerInfo": {
            "customerName": "xxxxxxxxxxx",
            "address": null
        },
        "invoiceList": {
            "any": [
                "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\n<item xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://www.sugarcrm.com/sugarcrm\" xmlns:tns=\"http://www.sugarcrm.com/sugarcrm\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"tns:invoice_details\">
<month xsi:type=\"xsd:string\">xxxxxxx5</month>
<invoice_number xsi:type=\"xsd:string\">xxxxxxxx</invoice_number>
<amount xsi:type=\"xsd:string\">xxxxxxxx</amount></item>"
            ],
            "arrayType": "tns:invoice_details[1]",
            "offset": null,
            "id": null,
            "href": null,
            "otherAttributes": {}
        },
        "totalAmount": null,
        "statusMessage": "Success"
    }

如何将此数组转换为 invoice_details 数组?

感谢你的帮助。

标签: xmlspring-bootsoapwsdlsoap-client

解决方案


推荐阅读