Dagger Integration

ModelMapper’s Dagger integration allows for the provisioning of destination objects to be delegated to a Dagger ObjectGraph during the mapping process.

Setup

To get started, add the modelmapper-dagger Maven dependency to your project:

<dependency>
  <groupId>org.modelmapper.extensions</groupId>
  <artifactId>modelmapper-dagger</artifactId>
  <version>3.0.0</version>
</dependency>

Usage

Let’s obtain a Dagger integrated Provider, which will delegate to an ObjectGraph whenever called:

Provider<?> daggerProvider = DaggerIntegration.fromDagger(objectGraph);

Then we can configure the Provider for to be used globally for a ModelMapper:

modelMapper.getConfiguration().setProvider(daggerProvider);

Or set the Provider to be used for a specific TypeMap:

typeMap.setProvider(daggerProvider);

The provider can also be used for individual mappings:

with(daggerProvider).map().someSetter(source.someGetter());