This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic