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 Da...@kp.org on 2002/11/22 20:35:01 UTC

Vectors in JavaBeans

My web service returns a JavaBean with a vector of another type of bean as 
a member. In other words I have a "FamilyBean" that contains a Vector of 
"MemberBeans".  With a Java web client this is not a problem, because the 
client "understands" what a Vector is. But I want to support all types of 
clients transparently.

Is my only option to alter my JavaBean to use an array instead of a 
Vector?

It is possible using type mapping to represent a Vector of objects as an 
array? (Without having to alter the beans?)

Is there some other solution to this problem?

 

Re: Vectors in JavaBeans

Posted by Tom Creighton <to...@lptg.com>.
The problem is not so much the mapping of vector.  At least, it is possible to map it to soap and back to java.  Also there is a mapping to/from c#.  It uses object [] to map to this.  I've attached some sample files.  The original service is in CustomerServicex.java.  I've cleaned this up from some real code I have so don't worry if there are minor compile errors or the class name doesn't match the file name.  The CustomerService class defines my web service.  One of the methods is getContactsByMemberID.  This method returns a Vector.  Presumably this will be filled with references to Contact objects.  Works great in java/rmi/ejb land.  Problem is that although a reasonable mapping happens to soap via a complex type called Vector that is unbounded and supports xsd:anyType, and although this maps reasonably to a c# type of object [], the problem happens at run time.   If I pass data through this that can't be serialized I get an exception.  Can't be predicted at compile time because Vector is a collection of 'untyped' objects.  OK, I know that Object is a type, but that's not the point.  You don't know if it's a Contact object that can be serialized or if it is some FooBar object that cannot be.  Plus, the wsdl doesn't know for sure what it is going across, so it can't for sure have described the complex type.

I've used C# as the sample client because I figure it's a reasonable test - service in java, client in c#.  I've decided to always create service interfaces that have completely typed collections.  This means mapping a vector to a typed array.  Shouldn't be a problem.  The service interface can still be non-specific relative to the number of elements of the array.  Plus, you aren't going to try to hand someone a reference to a collection for them to add to it anyway, so the point of a dynamic collection is lost anyway.  Only problem is if you really do have a collection of heterogeneous object types.  If so, you probably want to figure out a different service interface anyway. 

Hope this helps.  Also hope that the attachments come through on the list.  I'm more of a lurker, so contributing to lists is new to me.

tc


  ----- Original Message ----- 
  From: David.Pool@kp.org 
  To: axis-user@xml.apache.org 
  Sent: Friday, November 22, 2002 12:35 PM
  Subject: Vectors in JavaBeans



  My web service returns a JavaBean with a vector of another type of bean as a member. In other words I have a "FamilyBean" that contains a Vector of "MemberBeans".  With a Java web client this is not a problem, because the client "understands" what a Vector is. But I want to support all types of clients transparently. 

  Is my only option to alter my JavaBean to use an array instead of a Vector? 

  It is possible using type mapping to represent a Vector of objects as an array? (Without having to alter the beans?) 

  Is there some other solution to this problem?