471,354 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

XML JAXB Binding to Vector not List

I am attempting to create a JAXB Object that returns the
CollectionType as a List. In my schema file, I used the following:

<jxb:globalBindings>
collectionType="java.util.Vector"
</jxb:globalBindings>

This changed the initialization in the impl stub from the following:

protected com.sun.xml.bind.util.ListImpl _MyList = new
com.sun.xml.bind.util.ListImpl(new java.util.ArrayList());

to:
protected com.sun.xml.bind.util.ListImpl _MyList = new
com.sun.xml.bind.util.ListImpl(new java.util.Vector());

This looks better, but when I use the MyObject.getMyList() function,
it returns a java.util.List object. Not a java.util.Vector.

Is there anyway that I can cast it or change the function signature to
return a Vector?
Jul 17 '05 #1
1 6509

"Scott Bates" <sa*****@slocrusade.com> wrote in message
news:70**************************@posting.google.c om...
I am attempting to create a JAXB Object that returns the
CollectionType as a List. In my schema file, I used the following:

<jxb:globalBindings>
collectionType="java.util.Vector"
</jxb:globalBindings>

This changed the initialization in the impl stub from the following:

protected com.sun.xml.bind.util.ListImpl _MyList = new
com.sun.xml.bind.util.ListImpl(new java.util.ArrayList());

to:
protected com.sun.xml.bind.util.ListImpl _MyList = new
com.sun.xml.bind.util.ListImpl(new java.util.Vector());

This looks better, but when I use the MyObject.getMyList() function,
it returns a java.util.List object. Not a java.util.Vector.

Is there anyway that I can cast it or change the function signature to
return a Vector?


Is it returning a Vector.
It is returning a java.util.List reference to the Vector object.
This is the correct way to use the Collections API.
You should never (loosely speaking) create a reference to a List, Set or Map
implementation class (such as java.util.Vector).

You *can* cast it, but chances are, you don't want you.
Or ... you think you want to, but you don't understand that you would be
writing poor code.

The fact that you are changing List implementations (from ArrayList to
Vector) is a perfect example of why you want to handle the returned List
reference transparently (to the implementation).

Perhaps this will help:
http://java.sun.com/docs/books/tutor...tro/index.html

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by jesper | last post: by
reply views Thread by Brett Selleck | last post: by
1 post views Thread by =?Utf-8?B?VGVjaGVlaw==?= | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.