Search code examples
javasoapapache-axis

Axis2 / SOAP, return List<myIObject> produce empty return


So I have a piece of code producing a SOAP serivce in Java, wrapping some Python code through Jython over a Tomcat/Axis2 server... and it works!

I have a method that return a

   public static List<MyClass> doSomething()

but from the Soap answer I only get some empty data:

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
   <soapenv:Body>
      <ns:doMyServiceResponse xmlns:ns="http://mypyinterface" xmlns:ax23="http://mypyinterface/xsd">
     <ns:return xsi:type="ax23:MyClass" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
     <ns:return xsi:type="ax23:MyClass" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
     <ns:return xsi:type="ax23:MyClass" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
     <ns:return xsi:type="ax23:MyClass" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
     <ns:return xsi:type="ax23:MyClass" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
     <ns:return xsi:type="ax23:MyClass" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
     <ns:return xsi:type="ax23:MyClass" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
      </ns:doMyServiceResponse >
   </soapenv:Body>
</soapenv:Envelope>

I have found many posts on the subject on the web like complex types in axis2 - Map, How do I send an array or collection of complex objects using web services in Java (e.g. Axis2)? and many say that one can not get List as return, but only Array,

BUT, I do not understand, as I notice that the result above is actually an empty List with the right count of elements, if I ever decide to produce a List< String > as a result, then I get right values (is it because I am using a simple < String > Java type inside List?) without even changing anything to Array or ArrayList (while I have read that List can not be produced)

So I may have missed something else, is there any trick that I may have forgotten? Like changing my MyClass as a java.io.Serilizable or providing some specific method that can be used by Axis2 to have/produce right values in my XML output SOAP stream?

And is it possible to have a reply via Axis2 that will produce a List or not?


Solution

  • No, this is not possible. You can read a previous answer to this question here.

    In your case, you would return like this:

    public static MyClass[] doSomething()
    

    Just let the List.toArray() do the magic for you!