Search code examples
javaweb-servicesksoap2

kSOAP2: cast anyType to complexType in Java


I have a web service and I'm using kSOAP2 to send request and get response from this web service. I made class implements KvmSerializable in order to send complexTypes to the web service but when I'm getting a response I cannot cast it to my complexType. For example: I'm getting 'anyType' and I want to cast it to my class 'User' but then I'm getting a ClassCastException

cannot cast SoapObject to class User.

Is there any way to do it?

Thanks for any help in this case.


Solution

  • You must register your class with Soap envelope, some thing like this:

      envelope.addMapping(NAMESPACE, "user", User.class);
    

    Check this answer that worked for me.