Search code examples
castor

What is the usage of reference attribute in castor-xml mapping file?


I am using castor to bind java objects to XML. Following is an example mapping of an field attribute in my java object. Does anyone know what is the usage of reference attribute in bind-xml tag.

<field name="title" type="string" required="false"
        direct="false" transient="false">
        <bind-xml name="title" node="element" reference="false"/>
</field>

Solution

  • When reference is set to true, Castor knows to create only a reference to the object rather than a full object. This accomplishes two things: first, it reduces the size of the XML file created during marshalling because each object is completely written out only once, and two, on unmarshal, the objects will maintain the correct relations to each other.

    http://castor.codehaus.org/1.2/how-to-use-references-in-xml.html