Springboot Modelmapper Starter

'A Springboot starter for modelmapper'

Лицензия

Лицензия

Категории

Категории

Spring Boot Контейнер Микросервисы ModelMapper Универсальные библиотеки Bean Mapping
Группа

Группа

com.github.rozidan
Идентификатор

Идентификатор

modelmapper-spring-boot-starter
Последняя версия

Последняя версия

2.3.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

Springboot Modelmapper Starter
'A Springboot starter for modelmapper'
Ссылка на сайт

Ссылка на сайт

https://github.com/rozidan/modelmapper-spring-boot-starter.git
Организация-разработчик

Организация-разработчик

Idan Rozenfeld
Система контроля версий

Система контроля версий

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

Скачать modelmapper-spring-boot-starter

Как подключить последнюю версию

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

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.modelmapper : modelmapper jar 2.3.0

runtime (3)

Идентификатор библиотеки Тип Версия
org.springframework : spring-beans jar
org.springframework : spring-context jar
org.springframework.boot : spring-boot-autoconfigure jar

Модули Проекта

Данный проект не имеет модулей.

Spring Boot ModelMapper Starter

A Spring Boot starter that let you use ModelMapper within your Spring Boot application.

Base on jmnarloch modelmapper project with Modelmapper newest version adjustments.

Build Status Coverage Status

Maven Central Sonatype Nexus (Snapshots)

License

Features

Register the ModelMapper to your Spring Boot application and allows to configure it and register object mappings.

Setup

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

<dependency>
    <groupId>com.github.rozidan</groupId>
    <artifactId>modelmapper-spring-boot-starter</artifactId>
    <version>2.3.1</version>
</dependency>
compile 'com.github.rozidan:modelmapper-spring-boot-starter:2.3.1'

For snapshots versions add the sonatype public repository:

repositories {
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/groups/public" }
    ...
}

Change ModelMapper global configuration

In order to set change ModelMapper global configuration, simply register within Spring application context instance of MapperConfigurer:

@Component
public class GlobalConfiguration extends MapperConfigurer {
    @Override
    public void configure(Configuration configuration) {
        configuration.setSkipNullEnabled(true);
        configuration.setMatchingStrategy(MatchingStrategies.STRICT);
    }
}

Overriding the default mapping

In order to override the default mapping of some object types, lets say User -> UserDto, simply register within Spring application context instance of TypeMapConfigurer:

@Component
public class MapperConfigurer extends TypeMapConfigurer<User, UserDto> {
    @Override
    public void configure(TypeMap<User, UserDto> typeMap) {
        typeMap.addMapping(User::getAge, UserDto::setAge);
        typeMap.addMappings(mapping -> mapping.skip(UserDto::setMiddleName));
        typeMap.setPreConverter(context -> {
            String[] name = context.getSource().getName().split(" ");
            context.getDestination().setFirstName(name[0]);
            context.getDestination().setLastName(name[1]);
            return context.getDestination();
        });
        
    }
}

Custom converter

In order to register ModelMapper Converter, simply register within Spring application context instance of ConverterConfigurer:

@Component
public class SomeEnumTypeConverter extends ConverterConfigurer<ProductCategory, ProductCategoryDto> {
        @Override
        public Converter<ProductCategory, ProductCategoryDto> converter() {
            return new AbstractConverter<ProductCategory, ProductCategoryDto>() {
                @Override
                protected ProductCategoryDto convert(ProductCategory source) {
                    ...
                }
            };
        }
    }

Testing

Scan for mapping components with the WithModelMapper annotation

@RunWith(SpringRunner.class)
public class MapperTest {
    
    @Test
    public void someTest() {
        
    }
    
    @Configuration
    @WithModelMapper(basePackage = "com.company.program.mapping")
    public static class Application {
    }
}

License

Apache-2.0

Версии библиотеки

Версия
2.3.1
2.3.0
1.0.0