且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在axis2 - Map中的复杂类型

更新时间:2022-10-14 23:01:31

Java泛型(与数组类型相反)在编译期间被清除,因此对于Axis Map< String ,对[]> Map 相同。



在Java SOAP中表示关键对象映射的方法是使用对象包含其键的数组。



在您的情况下,如果您的地图由 Pair.key 值,然后使用 Pair [] 应该可以工作。


I m implementing web service using axis2. The problem i m facing is with returning a complex structure in one of the methods. Here is what i want to do:

as a return type - Map<String, Pair[]> where Pair is

    public class Pair {

        private String key;
        private String value;
...........
}

i m testing it with SoapUI

and the return is always empty here is a simple response i got

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns:getSNSTrendsResponse xmlns:ns="http://soap.sso.vwdcrm.app.mailprofiler.com">
         <ns:return xsi:type="ax211:SNSData" xmlns:ax212="http://util.java/xsd" xmlns:ax211="http://objects.soap.sso.vwdcrm.app.mailprofiler.com/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ax211:errorCode>1</ax211:errorCode>
            <ax211:errorMessage xsi:nil="true"/>
            <ax211:pairsResponse xsi:type="axis2ns2:anyType">
               <empty xmlns="http://www.w3.org/2001/XMLSchema">false</empty>
            </ax211:pairsResponse>
            <ax211:response xsi:nil="true"/>
         </ns:return>
      </ns:getSNSTrendsResponse>
   </soapenv:Body>
</soapenv:Envelope

where pairResponse should contains the result...

Java generics (contrary to arrays types for instance) are erased during compilation, thus for Axis Map<String, Pair[]> is the same thing as Map.

The usual way of representing key-to-object mapping in Java SOAP is to use an array where objects contain their key.

In your case, if your Map is indexed by Pair.key value, then using a Pair[] should work.