On Jul 22, 2008, at 10:41 PM, Kugaprakash Visagamani wrote:

Hi Dan,
Thanks a lot for the helpful suggestions.
I was thinking only in terms of interceptor, and breaking my head...
Anyways,
"MyList" is not an implementation of java.util.List, however, I can try
to convert it to implement java.util.List, so, question is, If I just
define "MyList" the following way:
Public interface MyList extends java.util.List{}

You MAY will need the generics in there as well:
public interface MyList<T> extends java.util.List<T> {....}
so JAXB can then determine what it is a list of.

Is that sufficient, or will there be any kind of ClassCastException
(like when the CXF unmarshal/marshal, would expect an
ArrayList/Vector/..)

No. THat should be fine. As long as it implements "List" and the appropriate "List<Item> getItem()" call is there, it should be fine. There is actually a JAXB customization that allows you to tell the code generator to use a different List implementation than ArrayList (the default). Thus, the runtime cannot rely on it as that customization wouldn't work.

Can I request your recommendations in terms of performance, which
approach would be better, weather to extend MyList to List, and then
annotate it, or use XmlJavaTypeAdapter?

Definitely the List approach. The TypeAdapter stuff requires you to write code to map your data into a List and back again. Thus, you end up copying stuff from List to List and constructing additional objects, etc.... If your list is just a List, it can use it as is.

Dan






Thanks Again,
Best Regards
Kuga

-----Original Message-----
From: Daniel Kulp [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 22, 2008 6:11 PM
To: [email protected]; Kugaprakash Visagamani
Subject: Re: Specifying my own collection for Marshalling/ Unmarshalling!


If "MyList" is a List, the easiest is to jst add a method:
public List<Item> getItems() {
    return items;
}
and move the JAXB annotations onto it instead of the field.   The
runtime will use that method to get the list.  It will use that to
call list.add(..) to populate it or the iterator to write it.   You
could actually return an object that implements List that wrappers
your real object.

If it DOESN'T implement the list, you'll need to write an
XmlJavaTypeAdapter that maps your type to/from the appropriate List.
The java_frist_jaxws sample shows one of those for mapping Maps.


Dan



On Jul 22, 2008, at 4:19 PM, Kugaprakash Visagamani wrote:

Hi,
In the WSDL definition, I have a list of items as given below:
Wsdl2Java converted java object sample is given below:

Public class Order {
        Private List<Item> items;

}

But my actual model class definition is:
Public class Order{
        Private MyList items; //MyList is my own implementation of List,
or may be it may not even be extending from the java.util.List, is
rather kind of implementation of list
}

Note: I am not planning to use the Wsdl2Java generated java objects,
instead I am placing my actual model class "Order" in the same package
as the Wsdl2Java generated java objects would be, so that during
searialization/de-serialization process, it actually pick my actual
model class. It all works fine, except for this kind of scenarios,
where
I have my own implementation of List.

Can I add some interceptor or define somewhere in the xml's that
during
the marshall/unmarshall if it encounter's List, use my implementation
instead.

Any sample code would be HIGHLY Appreciated.

Thanks in advance.
Best Regards,
Kuga

---
Daniel Kulp
[EMAIL PROTECTED]
http://www.dankulp.com/blog





---
Daniel Kulp
[EMAIL PROTECTED]
http://www.dankulp.com/blog




Reply via email to