users@jax-rpc.java.net

Re: Returning array of custom object -> NULL objects in array

From: Baltz, Kenneth <Kbaltz_at_FIRSTAM.COM>
Date: Fri, 06 Dec 2002 08:57:40 -0800

I know this one very well. I wasted 3 days tracking it down. It might be a
bug; I can't decide.

The way the JAX-RPC array deserializers are written looks something like
this:

// Using your code as an example
Profile [] profiles = new Profile[/* correct number of obejcts];

Object3.setProfiles( profiles ); // note that the array is unpopulated at
this point

for( int i = 0; i < profiles.length; i++ ) {
        profiles[i] = new Profile( ... );
        ... call Profile setters ...
}

The trouble is caused by the fact that you don't keep the Array reference
that is passed to your setter. The JAX-RPC implementation assumes that
getters/setters are basically the same as actual variables.

I believe the same behavior appears for Collections objects as well. I.e.
The object is passed to you before it's populated.

K.C.


> -----Original Message-----
> From: Pedro Salazar [mailto:pedro-b-salazar_at_PTINOVACAO.PT]
> Sent: Friday, December 06, 2002 3:23 AM
> To: JAXRPC-INTEREST_at_JAVA.SUN.COM
> Subject: Returning array of custom object -> NULL objects in array
>
>
> Greetings,
>
> I created a jaxrpc web service that returns a custom object which has
> two fields: a custom object2 and a array of custom object3 ( ->
> Profile[]). In my client, when I can retrieve the custom
> object2 ok, but
> when I try to get my array of custom object3, all the positions are
> null!
>
> My setX/getX of custom object3 are:
>
> private Profile[] profiles;
> public Profile[] getProfiles(){
> return this.profiles;
> }
> public void setProfiles(Profile[] profiles){
> if(profiles.length>0){
> this.profiles=new Profile[profiles.length];
>
> System.arraycopy(profiles,0,this.profiles,0,profiles.length);
> }
> }
>
> PS. the object Profile is a simple object with two fields (int,String)
> with a set/get to both of them.
>
> thanks for your attention,
> regards.
>
> --
> pedro salazar (pt-inovacao) <pedro-b-salazar_at_ptinovacao.pt>
> key id: D803BC61
>