Ali-
I have to admit, I have never found a good solution to this problem. I
almost always wrap the ArrayList inside another class, at which point
you can take advantage of the collection="arraylist" attribute in a
mapping file (and use nested class mappings if necessary).
One thought I do have, if (large caveat) you don't need to ever
unmarshall this list back into a Java object, is to list a field in the
mapping file (call it whatever) where you specify the
get-method="toArray", the type="Item", and the collection="array". At
that point Castor should recognize the Item class and use whatever
mapping you supply for it. Unfortunately, ArrayList doesn't have a
method "fromArray" or a constructor that takes in an array in order to
recreate the object, making this method unusable for unmarshalling.
One other possibility might be to use custom field handlers
(documentation on the Castor website), but I'm having a hard time
figuring out a slick way to approach the problem from that angle.
Perhaps someone else can shed some more light on any of these options.
HTH,
Stephen
Ali Emami wrote:
Hi everybody,
Lets say that I have a ArrayList and I want to marshall it to a xml file
with a mapping file so
I can get a result like this:
<resources num-items= x >
<resource id=1/>
<resource id=2/>
<resource id=3/>
<resource id=4/>
.
.
</resources>
And lets say my object is something like this
Public Class item {
String item,
String name,
//Setters and getters
}
Is it possible to do this?
I could get the num-items to work by doing something like this
<class name="java.util.ArrayList" auto-complete="false">
<map-to xml="resources"/>
<field name="size" get-method="size">
<bind-xml name="num-items" node="attribute"/>
</field>
.
.
.
But I can not customize the object fields
Thanks for your help
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------