Search code examples
javaandroidweb-servicessoapksoap2

Retrieve Class Object from SOAP envelope?


I have a web service that returns a single Class Object to me from a database query.. I know how to retrieve a property from the soapObject but, that property contains the object. So, for example if I use:

SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
        Object obj = resultsRequestSOAP.getProperty("return");

The objects entire value is: "Contacts{ id=value, username=value, location=value, date=value}"

The problem is: I can't do anything with this unless I want to break it up as a string using "split". I need to know how to get this object out of the envelope or SoapObject with types and values that I can work with. Any help would be much appreciated. I can post the source code if needed, but I don't think it's necessary for such a small problem.

EDIT: When I "watch" the SoapObject the breakdown is: the object has a property named "return" then this property has a value named "Contacts". This value as 4 properties which are my values that I need. Hope this helps.


Solution

  • It sounds like return is a nested soap object? I'm not that familiar with this particular library, but would something like this work?

    SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
    SoapObject returnObj = (SoapObject)resultsRequestSOAP.getProperty("return");
    Integer id = Integer.valueOf(returnObj.getProperty("id");
    String username = (String)returnObj.getProperty("value");
    ...
    

    If you put a breakpoint there somewhere, you should be able to inspect the objects to figure out exactly what type they are, and thus what casting is necessary.