![]() | ![]() | ![]() | ![]() | ![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | ![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]()
|
How to wrap a collection with a wrapper elementIntended Audience Prerequisites Basic concept Java entities Required XML output Mapping file Intended AudienceAnyone who wants to wrap a collection with a wrapper element. This document helps people to get familiar with the basic concepts and shows an example. PrerequisitesNone. Basic conceptWhen you have a field which is a list collection, and you want for each element of the list collection to be encapsulated in a containing element, then set container="false" in the field element for the list collection. By setting this attribute Castor recognizes that you want an element wrapping the members of the list. By default Castor treats collections as "containers". Containers to Castor are simple objects whose only purpose is to hold other objects. Containers are not considered "first-class" objects and therefore have no direct XML representation. By setting container="false", you are telling Castor that the collection is not be treated as a container, but rather a first class object which should have an XML-representation. Java entitiesFor example, if you have the following two classes:
Required XML outputand you want to have Castor generate XML which looks like:
Mapping filethen you would use a mapping like:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() ![]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |