Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 35764 invoked from network); 11 Jun 2005 14:27:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 11 Jun 2005 14:27:58 -0000 Received: (qmail 40245 invoked by uid 500); 11 Jun 2005 14:27:54 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 40216 invoked by uid 500); 11 Jun 2005 14:27:53 -0000 Mailing-List: contact axis-dev-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@ws.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-dev@ws.apache.org Received: (qmail 40198 invoked by uid 99); 11 Jun 2005 14:27:53 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from ajax-1.apache.org (HELO ajax.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.28) with ESMTP; Sat, 11 Jun 2005 07:27:51 -0700 Received: from ajax.apache.org (ajax.apache.org [127.0.0.1]) by ajax.apache.org (Postfix) with ESMTP id 1289A15 for ; Sat, 11 Jun 2005 16:27:47 +0200 (CEST) Message-ID: <1003254343.1118500067074.JavaMail.jira@ajax.apache.org> Date: Sat, 11 Jun 2005 16:27:47 +0200 (CEST) From: "Davanum Srinivas (JIRA)" To: axis-dev@ws.apache.org Subject: [jira] Resolved: (AXIS-1413) Axis deserialization of Arrays In-Reply-To: <1205405571.1088059649734.JavaMail.apache@nagoya> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N [ http://issues.apache.org/jira/browse/AXIS-1413?page=all ] Davanum Srinivas resolved AXIS-1413: ------------------------------------ Resolution: Fixed Applied patch. thanks, dims > Axis deserialization of Arrays > ------------------------------ > > Key: AXIS-1413 > URL: http://issues.apache.org/jira/browse/AXIS-1413 > Project: Apache Axis > Type: Bug > Components: Serialization/Deserialization > Versions: 1.2 Beta > Environment: Win2k Advanced server > Reporter: Vikram Roopchand > Assignee: Davanum Srinivas > > Hi, > we are facing a peculiar problem. We have a setter and getter for > java.lang.Object[], something like this :- > void setValues(Object[] values); > Object[] getValues(); > We use this to send/receive arrays of any type > (Integer,String,Float,MyClassA,YourClassB). WSDL generated for such code > via java2WSDL has array of xsd:anyType for this, which is okay. > When the SOAP xml(via RPC) is sent from the Client (using Axis) it gets > represented by it's XSD type for e.g.:- > Please look at "values" element. > soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" > xmlns:ns17="http://localhost:8080/Contentbiz/sysTypes" > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" > xsi:type="ns17:CBAttributeValue"> > ct_NoOfEmployees > > > 12 > 14 > > true > true > false > > Our system is built in such a way that we use the Getter on the Server > end and the "Type" (also sent from the client) and work with the Array > so returned . > Somewhat like:- > //identify the data type > DataType dataType = deserializedObject.getDataType(); > //retrieve the "typed" array > getTypedArray(dataType,deserializedObject.getValues()); > Now comes our problem :- > For all the Types which are our types (MyClassA,MyClassB) , the > deserialiazedObject contains an array of the proper type , getValues > will return an array of MyClassA objects. > For Other types like Integer/Float/Boolean (not String) it is returning > Object[] having the properly typed values within, which results for us > into a ClassCastException for us when we use our getTypedArray method > (this method assumes that Axis will return the correctly typed array). > The Subsystem (Axis) in BeanPropertyTarget.set() handles it in such a > way:- > try { > // Set the value on the bean property. > // Use the indexed property method if the > // index is set. > if (index < 0) { > pd.set(object, value); > } else { > pd.set(object, index, value); > } > } catch (Exception e) { > try { > // If an exception occurred, > // see it the value can be converted into > // the expected type. > Class type = pd.getType(); > > if (JavaUtils.isConvertable(value, type)) { > value = JavaUtils.convert(value, type); > if (index < 0) > pd.set(object, value); > else > pd.set(object, index, value); > } else { > // It is possible that an indexed > // format was expected, but the > // entire array was sent. In such > // cases traverse the array and > // call the setter for each item. > if (index == 0 && > value.getClass().isArray() && > !type.getClass().isArray()) { > for (int i=0; i Object item = > JavaUtils.convert(Array.get(value, i), > type); > pd.set(object, i, item); > } > } else { > // Can't proceed. Throw an exception that > // will be caught in the catch block below. > throw e; > } > } > In the CATCH block (It will come here for all basic xsd types , as code > executed before it in ArrayListExtension marks it to be a int[] array > and the setValues(Object[]) will fail with IllegalArgumentException), it > is attempted to figure out the Type and Convert it to the one in the > BeanPropertyDescriptor (which for us is Object[] class, which is okay > since it is an anyType). But there is a small deviation , instead of > identifying the underlying type (if it is an array) , CATCH block > creates an array of Object[] and fills it up with the values of correct > type. This results in the deserilialzedObject.getValues() resulting in > an Object[] array instead of an Integer[] (as expected). > This is a discrepancy as for some XSD types like xsd:string, > xsd:dateTime it returns String[]/Calendar[] but for > xsd:int,xsd:float,xsd:boolean etc. it does not. > We would like to confirm whether or not do you consider this as a bug , > we did a slight modification to CATCH BeanPropertyTarget and everthing > was working fine , :- > catch { > // If an exception occurred, > // see it the value can be converted into > // the expected type. > Class type = pd.getType(); > > //Vikram - INFY - START > if (value.getClass().isArray() && > value.getClass().getComponentType().isPrimitive() > && type.isArray() && > type.getComponentType().equals(Object.class)) > { > //we make our own array type here. > type = > Array.newInstance(JavaUtils.getWrapperClass(value.getClass().getComponen > tType()),0).getClass(); > } > //Vikram - INFY - END > if (JavaUtils.isConvertable(value, type)) { > value = JavaUtils.convert(value, type); > if (index < 0) > pd.set(object, value); > else > pd.set(object, index, value); > } else { > // It is possible that an indexed > // format was expected, but the > // entire array was sent. In such > // cases traverse the array and > // call the setter for each item. > if (index == 0 && > value.getClass().isArray() && > !type.getClass().isArray()) { > for (int i=0; i Object item = > JavaUtils.convert(Array.get(value, i), > type); > pd.set(object, i, item); > } > } else { > // Can't proceed. Throw an exception that > // will be caught in the catch block below. > throw e; > } > } > Only for primitive Arrays,We change the "type" to take in the underlying > type of the "value" array. This will work only for primitive arrays and > only when the bd has "type" set to Object[] (anytype). > I would appreciate a quick response from your side as most of our system > depends on this functionality. > Thanks a lot, > Vikram Roopchand > Programmwer Analyst, > INFOSYS Technologies Ltd. - Pune. > India -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira