Search code examples
javamappingcollectionscastor

Using Castor, how do you map Java class "java.util.ArrayList" to element "ArrayList", but also generate elements for the objects that it contains?


Using Castor, how do you map Java class java.util.ArrayList to element <ArrayList/> instead of <array-list/> while still including the elements that it contains?

For example, the class mapping

<class name="java.util.ArrayList">
    <map-to xml="ArrayList" />
</class>

maps an ArrayList object to an empty element, omitting elements for the objects that the ArrayList may contain. How do you coerce Castor into also generating elements for those contained objects?


Solution

  • Add attribute autocomplete="true" to the mapping:

    <class name="java.util.ArrayList" auto-complete="true">
        <map-to xml="ArrayList" />
    </class>
    

    See description of auto-complete under Section <class/> in Castor XML Mapping.