public interface EventListener {
publicvoid onMappingStarted(Event event);
public void onPreWritingDestinationValue(Event event);
public void onPostWritingDestinationValue(Event event);
public void onMappingFinished(Event event);
}
Event Listening
By implementing the EventListener interface dozer allows you to listen to
4 different events:
-
mappingStarted -
mappingFinished -
preWritingDestinationValue -
postWritingDestinationValue
An Event 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:
The listeners that you create can be injected into the Mapper
using an IOC like Spring or set directly during Mapper instance configuration
using DozerBeanMapperBuilder#withEventListener(..) 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="com.github.dozermapper.core.DozerBeanMapper">
<property name="mappingFiles">
<list>
<value>dozerBeanMapping.xml</value>
</list>
</property>
<property name="eventListeners">
<list>
<ref bean="eventTestListener" />
</list>
</property>
</bean>
<bean id="eventTestListener" class="com.github.dozermapper.core.event.EventTestListener" />
</beans>