Fork me on GitHub

Event Listening

By implementing the DozerEventListener interface dozer allows you to listen to 4 different events:

  • mappingStarted
  • mappingFinished
  • preWritingDestinationValue
  • postWritingDestinationValue

A DozerEvent object is passed into these callback methods which stores information about the ClassMap, FieldMap, Source object, destination object, and destination value. This will allow you to extend dozer and manipulate mapped objects at run-time. The interface is shown below:

public interface DozerEventListener {
  public void mappingStarted(DozerEvent event);
  public void preWritingDestinationValue(DozerEvent event);
  public void postWritingDestinationValue(DozerEvent event);
  public void mappingFinished(DozerEvent event);

The listeners that you create can be injected to the DozerBeanMapper using an IOC like Spring or set directly on your DozerBeanMapper instance by using the setEventListeners() method. Below is an example using Spring to inject an event listener:

<?xml version="1.0" encoding="UTF-8"?>
<beans default-lazy-init="false">
 <bean id="EventMapper" class="org.dozer.DozerBeanMapper">
  <property name="mappingFiles">
  <property name="eventListeners">
    <ref bean="eventTestListener"/>
 <bean id="eventTestListener"