---------- Forwarded message ---------- From: June Fang <[EMAIL PROTECTED]> Date: Jan 31, 2007 11:48 AM Subject: Re: Array as return value: workaround? To: DATACOM - Diego <[EMAIL PROTECTED]>
Hi Diego, I have left my previous company so i can not got the code snips easily at hand. But the guide line is as follows: see this message: http://mail-archives.apache.org/mod_mbox/ws-xmlrpc-dev /200609.mbox/%3c19c34bd10609220254uff2b4f1g5dd8a7d39e0303b2 @mail.gmail.com%3e "it's the array's element type that causing the ClassCastException", in another words, it means that you can cast the result to Object[] but not String[]. so for the following method, String[] returnStringArray(), the return type is actually an array but of the improper element type(indeed its elements is of the generic type java.lang.Object), so when you cast Object[] to String[], there is an ClassCastException. my solution is using java.lang.reflect.Array to fetch the individuals elements from the Object[] one by one, and cast them from Object to String, then fill the result String into an String[] created using reflection. and finally return the String[]. Then all done, now the array is of proper element type(in this case String). Hope that would help. On 1/25/07, DATACOM - Diego <[EMAIL PROTECTED]> wrote:
Hi all, I am using XML-RPC 3.0rc1 and Java 1.5.0_06. I am getting a ClassCastException every time I try to return an array, List or Vector. I think it is related to this bug: http://issues.apache.org/jira/browse/XMLRPC-129 I would like to know if there is any workaround to this bug. In this message, there something about using reflection to operate on the result: http://mail-archives.apache.org/mod_mbox/ws-xmlrpc-dev /200609.mbox/%3c19c34bd10609220214g170174e2mdb9082f1aacb0537 @mail.gmail.com%3e Anybody knows how to do it using reflection? I am following a specification, so I cannot use other solutions like using a Map in the place of the array. Thanks in advance, -- DIEGO Moreira da Rosa DATACOM Av França, 735 - Porto Alegre, RS - 90230-220 DDR: +55 51 3358 0141 Fax: +55 51 3358 0101 site: www.datacom.ind.br e-mail: [EMAIL PROTECTED]
-- June Fang -- June Fang