17.6.2Mapping
Although it is possible to rely on Castor’s default marshalling behavior, it might be necessary to have more control over it. This can be accomplished using a Castor mapping file. For more information, refer toCastor XML Mapping.
The mapping can be set using themappingLocationresource property, indicated below with a classpath resource.
<beans>
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller" >
<property name="mappingLocation" value="classpath:mapping.xml" />
</bean>
</beans>
XML Schema-based Configuration
Thecastor-marshallertag configures aorg.springframework.oxm.castor.CastorMarshaller. Here is an example:
<oxm:castor-marshaller id="marshaller"
mapping-location="classpath:org/springframework/oxm/castor/mapping.xml"/>
The marshaller instance can be configured in two ways, by specifying either the location of a mapping file (through themapping-locationproperty), or by identifying Java POJOs (through thetarget-classortarget-packageproperties) for which there exist corresponding XML descriptor classes. The latter way is usually used in conjunction with XML code generation from XML schemas.
Available attributes are:
| Attribute | Description | Required |
|---|---|---|
id |
the id of the marshaller | no |
encoding |
the encoding to use for unmarshalling from XML | no |
target-class |
a Java class name for a POJO for which an XML class descriptor is available (as generated through code generation) | no |
target-package |
a Java package name that identifies a package that contains POJOs and their corresponding Castor XML descriptor classes (as generated through code generation from XML schemas) | no |
mapping-location |
location of a Castor XML mapping file |