Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.jmnarloch:modelmapper-spring-boot-starter:1.1.0'
}
dependencies {
implementation("com.github.jmnarloch:modelmapper-spring-boot-starter:1.1.0")
}
<dependency>
<groupId>com.github.jmnarloch</groupId>
<artifactId>modelmapper-spring-boot-starter</artifactId>
<version>1.1.0</version>
</dependency>
libraryDependencies += "com.github.jmnarloch" % "modelmapper-spring-boot-starter" % "1.1.0"
:dependencies [[com.github.jmnarloch/modelmapper-spring-boot-starter "1.1.0"]]
A Spring Boot starter that will help you configure ModelMapper within the application context.
Registers the ModelMapper as a Spring bean and allows to configure it and register specific object mappings.
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>
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);
}
}
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]);
}
};
}
}
Apache 2.0