You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by "David J." <da...@styleflare.com> on 2010/04/26 20:44:23 UTC

Return Complex Types.

How do I access an Array that is returned in a HashMap?

The server returns a HashMap with the following values

{responseCode=OK,people=[Array of People]}

I cast the response to a HashMap which then lets me access the  objects 
by key,
although the Array simple returns Object, and I cant access the Data.

ie I call

HashMap response = (HashMap)client.execute("myMethod",param);

String responseCode =  (String)response.get("responseCode");
System.out.println(responseCode); (Prints "OK");

Object[] people = (Object[]) response.get("people");
System.out.println(people); (Prints java.lang.Object);

Anyone can help me?

Re: Return Complex Types.

Posted by "David J." <da...@styleflare.com>.
Thanks both for your help, I could do that, I was just wondering if 
there was a method like setDebug(true) that may have been a helper method.

But I can get it that way also.

Thanks.

(I just think that the call was returning an empty Array. I made another 
call and it worked)



On 4/26/10 4:11 PM, Craig Kelley wrote:
> On Mon, Apr 26, 2010 at 2:07 PM, Stanislav Miklik
> <st...@gmail.com>  wrote:
>    
>> hm, try wireshark or something similar. I don't know better solution.
>>      
> Seconded.  Capture the session in Wireshark, and then follow the TCP
> stream.  You will then see both the XMLPRC request and response, and
> it will probably become obvious what is going on.
>
>    -Craig
>
>    


Re: Return Complex Types.

Posted by Craig Kelley <na...@gmail.com>.
On Mon, Apr 26, 2010 at 2:07 PM, Stanislav Miklik
<st...@gmail.com> wrote:
> hm, try wireshark or something similar. I don't know better solution.

Seconded.  Capture the session in Wireshark, and then follow the TCP
stream.  You will then see both the XMLPRC request and response, and
it will probably become obvious what is going on.

  -Craig

-- 
http://inconnu.islug.org/~ink finger  ink@inconnu.islug.org for PGP block

Re: Return Complex Types.

Posted by Stanislav Miklik <st...@gmail.com>.
hm, try wireshark or something similar. I don't know better solution.

On Mon, Apr 26, 2010 at 21:54, David J. <da...@styleflare.com> wrote:

> Thanks for your help Stano,
>
> I try to access the object by index, (people[0]) but I get an index out of
> bounds exception.
>
> Is there a way I can set debug on the response to see the raw method
> response?
>
> Thanks.
>
>
>
> On 4/26/10 3:12 PM, Stanislav Miklik wrote:
>
>> Hi,
>>
>> since you don't get a class cast exception, everything seems to be working
>> as it should be.
>> in your print you probably get something like [Ljava.lang.Object;@1100d7a
>> but this means that you have array of Objects
>>
>> Thus you can access the first person as people[0].
>> The corresponding type will be based on how the "array of people" was
>> constructed.
>>
>> BR
>> Stano
>>
>> On Mon, Apr 26, 2010 at 20:44, David J.<da...@styleflare.com>  wrote:
>>
>>
>>
>>> How do I access an Array that is returned in a HashMap?
>>>
>>> The server returns a HashMap with the following values
>>>
>>> {responseCode=OK,people=[Array of People]}
>>>
>>> I cast the response to a HashMap which then lets me access the  objects
>>> by
>>> key,
>>> although the Array simple returns Object, and I cant access the Data.
>>>
>>> ie I call
>>>
>>> HashMap response = (HashMap)client.execute("myMethod",param);
>>>
>>> String responseCode =  (String)response.get("responseCode");
>>> System.out.println(responseCode); (Prints "OK");
>>>
>>> Object[] people = (Object[]) response.get("people");
>>> System.out.println(people); (Prints java.lang.Object);
>>>
>>> Anyone can help me?
>>>
>>>
>>>
>>
>>
>
>

Re: Return Complex Types.

Posted by "David J." <da...@styleflare.com>.
Thanks for your help Stano,

I try to access the object by index, (people[0]) but I get an index out 
of bounds exception.

Is there a way I can set debug on the response to see the raw method 
response?

Thanks.


On 4/26/10 3:12 PM, Stanislav Miklik wrote:
> Hi,
>
> since you don't get a class cast exception, everything seems to be working
> as it should be.
> in your print you probably get something like [Ljava.lang.Object;@1100d7a
> but this means that you have array of Objects
>
> Thus you can access the first person as people[0].
> The corresponding type will be based on how the "array of people" was
> constructed.
>
> BR
> Stano
>
> On Mon, Apr 26, 2010 at 20:44, David J.<da...@styleflare.com>  wrote:
>
>    
>> How do I access an Array that is returned in a HashMap?
>>
>> The server returns a HashMap with the following values
>>
>> {responseCode=OK,people=[Array of People]}
>>
>> I cast the response to a HashMap which then lets me access the  objects by
>> key,
>> although the Array simple returns Object, and I cant access the Data.
>>
>> ie I call
>>
>> HashMap response = (HashMap)client.execute("myMethod",param);
>>
>> String responseCode =  (String)response.get("responseCode");
>> System.out.println(responseCode); (Prints "OK");
>>
>> Object[] people = (Object[]) response.get("people");
>> System.out.println(people); (Prints java.lang.Object);
>>
>> Anyone can help me?
>>
>>      
>    


Re: Return Complex Types.

Posted by Stanislav Miklik <st...@gmail.com>.
Hi,

since you don't get a class cast exception, everything seems to be working
as it should be.
in your print you probably get something like [Ljava.lang.Object;@1100d7a
but this means that you have array of Objects

Thus you can access the first person as people[0].
The corresponding type will be based on how the "array of people" was
constructed.

BR
Stano

On Mon, Apr 26, 2010 at 20:44, David J. <da...@styleflare.com> wrote:

> How do I access an Array that is returned in a HashMap?
>
> The server returns a HashMap with the following values
>
> {responseCode=OK,people=[Array of People]}
>
> I cast the response to a HashMap which then lets me access the  objects by
> key,
> although the Array simple returns Object, and I cant access the Data.
>
> ie I call
>
> HashMap response = (HashMap)client.execute("myMethod",param);
>
> String responseCode =  (String)response.get("responseCode");
> System.out.println(responseCode); (Prints "OK");
>
> Object[] people = (Object[]) response.get("people");
> System.out.println(people); (Prints java.lang.Object);
>
> Anyone can help me?
>