This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes XML and Related Technologies and the fly likes Castor: How to map list items within a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Castor: How to map list items within a "parent" list element?" Watch "Castor: How to map list items within a "parent" list element?" New topic
Author

Castor: How to map list items within a "parent" list element?

James Adams
Ranch Hand

Joined: Sep 12, 2003
Posts: 188
I am trying to map a List but have yet to work out the correct Castor mapping. When I let Castor auto-complete the class which contains the List I get all of the elements of the list at the same level. For example if my object contains a List of two elements I will get XML which looks like the following:

<my-object>
<list-element>
<element-field/>
</list-element>
<list-element>
<element-field/>
</list-element>
</my-object>

Instead I am trying to get XML which looks like this:

<my-object>
<my-list>
<list-element>
<element-field/>
</list-element>
<list-element>
<element-field/>
</list-element>
</my-list>
</my-object>


I have tried using a mapping.xml with the following entry:

<class name="MyObject"
auto-complete="true">
<!--
<field name="myList"
collection="arraylist"
type="MyListClass"/>
-->
</class>

I get the first example XML whether or not I use the <field> element in the <class> mapping element above.

The List member of the class I'm mapping is actually a List<E>, in that it is a List of objects of a class which is also mapped in the mapping.xml. Maybe Castor doesn't yet support generics, but I haven't seen anything to that effect in the documentation.

Also I have tried using bind-xml but the bind doesn't have the effect of nesting all of the list item elements within a "parent" list element, which is what I'm trying to achieve, instead it renames the list elements to whatever is specified as the bind-xml name.

Can someone steer me in the right direction? Thanks in advance for any suggestions!


--James
 
 
subject: Castor: How to map list items within a "parent" list element?