Spring Boot Starter ModelMapper

Spring Boot starter for ModelMapper

License

License

Categories

Categories

Spring Boot Container Microservices ModelMapper General Purpose Libraries Bean Mapping
GroupId

GroupId

com.github.jmnarloch
ArtifactId

ArtifactId

spring-boot-starter-modelmapper
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Spring Boot Starter ModelMapper
Spring Boot starter for ModelMapper
Project URL

Project URL

https://github.com/jmnarloch/spring-boot-starter-modelmapper
Source Code Management

Source Code Management

https://github.com/jmnarloch/spring-boot-starter-modelmapper.git

Download spring-boot-starter-modelmapper

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.jmnarloch/spring-boot-starter-modelmapper/ -->
<dependency>
    <groupId>com.github.jmnarloch</groupId>
    <artifactId>spring-boot-starter-modelmapper</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.jmnarloch/spring-boot-starter-modelmapper/
implementation 'com.github.jmnarloch:spring-boot-starter-modelmapper:1.0.0'
// https://jarcasting.com/artifacts/com.github.jmnarloch/spring-boot-starter-modelmapper/
implementation ("com.github.jmnarloch:spring-boot-starter-modelmapper:1.0.0")
'com.github.jmnarloch:spring-boot-starter-modelmapper:jar:1.0.0'
<dependency org="com.github.jmnarloch" name="spring-boot-starter-modelmapper" rev="1.0.0">
  <artifact name="spring-boot-starter-modelmapper" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.jmnarloch', module='spring-boot-starter-modelmapper', version='1.0.0')
)
libraryDependencies += "com.github.jmnarloch" % "spring-boot-starter-modelmapper" % "1.0.0"
[com.github.jmnarloch/spring-boot-starter-modelmapper "1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.modelmapper : modelmapper jar 0.7.4
org.springframework.boot : spring-boot-starter jar 1.2.5.RELEASE

test (3)

Group / Artifact Type Version
org.mockito : mockito-all jar 1.10.19
junit : junit jar 4.12
org.springframework.boot : spring-boot-starter-test jar 1.2.5.RELEASE

Project Modules

There are no modules declared in this project.

Spring Boot ModelMapper starter

A Spring Boot starter that will help you configure ModelMapper within the application context.

Build Status Coverage Status

Features

Registers the ModelMapper as a Spring bean and allows to configure it and register specific object mappings.

Setup

In order to add ModelMapper to your project simply add this dependency to your classpath:

<dependency>
    <groupId>com.github.jmnarloch</groupId>
    <artifactId>modelmapper-spring-boot-starter</artifactId>
    <version>1.1.0</version>
</dependency>

Additional configuration

If you need to set additonal configuration options simply register within Spring application context instance of ModelMapperConfigurer

@Component
public class CustomConfigurer implements ModelMapperConfigurer {
 
       void configure(ModelMapper modelMapper) {
           modelMapper.getConfiguration()
               .setSourceNamingConvention(NamingConventions.NONE);
               .setDestinationNamingConvention(NamingConventions.NONE);
       }
  }
  

Overriding the default mapping

Similarly registering the mapping can be performed through extending PropertyMapConfigurerSupport class.

@Component
public class UserDtoMapping extends PropertyMapConfigurerSupport<User, UserDto> {

   @Override
   public PropertyMap<User, UserDto> mapping() {

       return new PropertyMap<User, UserDto>() {
           @Override
           protected void configure() {
               map().setName(source.getFirstName());
           }
       };
   }
}
  

Additionally custom ModelMapper's converters can be registered:

@Component
public class UserDtoConverter extends ConverterConfigurerSupport<User, UserDTO> {
    @Override
    protected Converter<User, UserDTO> converter() {
        return new AbstractConverter<User, UserDTO>() {

            @Override
            protected UserDTO convert(User source) {
                String[] parts = source.getName().split(" ");
                return new UserDTO(parts[0], parts[1]);
            }
        };
    }
}

License

Apache 2.0

Versions

Version
1.0.0