Fork me on GitHub

Querying mapping metadata

This section will cover the mapping metadata interface. It provides easy to use read-only access to all important properties or aspects of the currently active mapping definitions.

The following sections will give some code examples how to use the mapping query interfaces. The most important interface in the whole process is org.dozer.metadata.MappingMetadata. An instance can be acquired by calling the getMappingMetadata() method of the DozerBeanMapper class. This call will initialize the mappings if the map method has not been called yet.

Consider the following mapping file:

<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns=""


To begin querying the mapping definitions the following code is needed:

DozerBeanMapper mapper = new DozerBeanMapper();
MappingMetadata mapMetadata = beanMapper.getMappingMetadata();

Now that a reference to MappingMetadata is obtained we can start querying for a certain class mapping definition:

try {
  ClassMappingMetadata classMappingMetadata = 
      mapMetadata.getClassMapping(ClassA.class, ClassB.class);
} catch (MetadataLookupException e) {
  // couldn't find it

When holding a reference to a ClassMappingMetadata interface, queries for individual field mappings can be executed:

try {
  FieldMappingMetadata fieldMetadata = 
  // Destination: fieldB
  System.out.println("Destination: " + 
} catch (MetadataLookupException e) {
  // couldn't find it

For extensive documentation on the different interfaces please refer to the JavaDoc.