Spring Integration

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

Setup

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

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

Usage

Let’s obtain a Spring integrated Provider, which will delegate to a BeanFactory whenever called:

Provider<?> springProvider = SpringIntegration.fromSpring(beanFactory);

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

modelMapper.getConfiguration().setProvider(springProvider);

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

typeMap.setProvider(springProvider);

The provider can also be used for individual mappings:

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