Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/jmnarloch/modelmapper-spring-boot-starter
- Owner: jmnarloch
- License: apache-2.0
- Created: 2015-08-11T19:22:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-11-06T14:38:48.000Z (about 6 years ago)
- Last Synced: 2023-11-07T20:41:26.205Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 99.6 KB
- Stars: 118
- Watchers: 12
- Forks: 27
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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