You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by James Oisin Flynn <de...@hotmail.com> on 2011/01/31 20:18:40 UTC

Axis2: Problem deserializing typed array on server "renamed"

Hello, I raised this problem earlier in the following post but have had no answers. I have noted other people having similar problems but have not found any suggested work-arounds yet.Am I doing something wrong?
Is there a known solution to the following problem short of encoding and decoding XML data myself?
Is this a known issue, and is there a time line to address it?
regards,James.
From: den.galna.kon@hotmail.com
To: java-user@axis.apache.org
Subject: Axis2: Bug unmarshalling an array of pojo objects with Axis2 web service.
Date: Fri, 21 Jan 2011 15:15:48 +0100








I have a small souci with the passing of an array of pojos my webservice. Axis version 1.5.1 with Eclipse and Tomcat.
The object in question takes this form:
class AnObject {        private String name;        private String title;        private int type;        //...
	public AnObject(){}
        public AnObject( String name )	{		this.name = name;	}
        public void setName( String name )        {		this.name = name;        }        public String getName() { return name; }
        public void setTitle( String title )        {                this.title = title;        }        public String getTitle() { return title; }
        public void setType( int type )        {                this.type = type;        }        public int getType() { return type; }
        public String toString() { return getTitle(); }}

The web service in question has a function:

public void doStuff( SessionId sessionId, AnObject[] theObjects ){        //....}

My problem comes when I enter this function: The array of objects I have is not the same as the array passed. The read objects are:

AnObject[0]   name = "title 1"                    title = null                    type = 0                    ...
AnObject[1]   name = "title 2"                    title = null                    type = 0                    ...

Now the reason this happens is the following:
In the class org.apache.axis2.databinding.utils.BeanUtil the deserialize() method reads my array perfectly. The ProcessElement() method builds the object just as I expect them.However, when it finishes constructing a list of AnObjects, it then attempts to build an array AnObject[] calling ConverterUtil.convertToArray( Class, List )Here, quite disastrously it calls the static method ConvertToArbitraryObjectArray() which takes my array of objects and does the following to them.
                        Array.set(returnArray, i, getObjectForClass(                                baseArrayClass,                                o.toString()));
getObjectForClass():            Constructor stringConstructor = clazz.getConstructor(new Class[] { String.class });            return stringConstructor.newInstance(new Object[] { value });
So by cloning my original objects, and calling the one arg constructor.
There might be a good reason for why it attempts to clone perfectly constructed objects, but for me this is an unmitigated disaster.I could potentially get around this by having AnObject implement the ADBBean interface, and hence not pass through this code, and execute the correct:
        try {            objectList.toArray((Object[])returnArray);        } catch (Exception e) {            //we are over with alternatives - throw the            //converison exception            throw new ObjectConversionException(e);        }
But this is not really an option. Having a dependency on the axis.jar will set off my twitch.
Is there a work around for this, or am I doing something incorrectly?Is there a work around for this that won't start me twitching?
Regards,James.