Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Spring Boot Starter for ModelMapper http://modelmapper.org
https://github.com/jmnarloch/modelmapper-spring-boot-starter

Last synced: 4 days ago
JSON representation

Spring Boot Starter for ModelMapper http://modelmapper.org

Awesome Lists containing this project

README

        

# Spring Boot ModelMapper starter

> A Spring Boot starter that will help you configure [ModelMapper](http://modelmapper.org) within the application context.

[![Build Status](https://travis-ci.org/jmnarloch/modelmapper-spring-boot-starter.svg?branch=master)](https://travis-ci.org/jmnarloch/modelmapper-spring-boot-starter)
[![Coverage Status](https://coveralls.io/repos/jmnarloch/modelmapper-spring-boot-starter/badge.svg?branch=master&service=github)](https://coveralls.io/github/jmnarloch/modelmapper-spring-boot-starter?branch=master)

## 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:

```xml

com.github.jmnarloch
modelmapper-spring-boot-starter
1.1.0

```

## Additional configuration

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

```java

@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.

```java

@Component
public class UserDtoMapping extends PropertyMapConfigurerSupport {

@Override
public PropertyMap mapping() {

return new PropertyMap() {
@Override
protected void configure() {
map().setName(source.getFirstName());
}
};
}
}

```

Additionally custom ModelMapper's converters can be registered:

```java

@Component
public class UserDtoConverter extends ConverterConfigurerSupport {
@Override
protected Converter converter() {
return new AbstractConverter() {

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

```

## License

Apache 2.0