• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic