nextObj = output.getObjectPart(potentialArrayObject);
int length = 0;boolean array = true;
try{
length = Array.getLength(nextObj);
}
catch(IllegalArgumentException iae){
System.out.println("The output is not an array");
array=false;
}
if(!array)
{
//It's just an object
// not an array
System.out.println("It's not an array");
System.out.println(nextObj);
}
else
{
// It's an array
System.out.println("It's an array");
Object nextArrObj=null;
for(int i =0;i<length;i++)
{
nextArrObj = Array.get(nextObj,i);
System.out.println(nextArrObj.getClass());
System.out.println(nextArrObj);
}
}
Hope someone gets some use out of this. If there's a more graceful way of determining if an objects an array without catching the exception I'd love if someone could post it.
Thanks,
Mark.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: 24 June 2003 18:04
To: [EMAIL PROTECTED]
Subject: Re: Array return typesFolks,I've done a little tinkering around and it turns out that what actually gets returned is an array of the primitive type.So I've got an EJB bean that's exposed as a web service and it's returning a Double array yet when the call returns, theoutput's ObjectPart corresponding to the right name only casts to the primitive type, (double [ ]).I get a class cast exception thrown if I attempt to cast to the wrapper object (Double []).This could unfortunately mean a series of instanceof if statements that could potentially be a bit of a nightmare.There's a reflective Array class java.lang.reflect.Array that exists for arrays of objects unfortunatelythere doesn't seem to be anything available for simple primitive arrays.Has anyone any ideas on how to get around this reflectively?Thanks in advance,Mark.
