Using ModelMapper Library in Spring Boot App
Step 1: Add ModelMapper Library Dependency
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>3.1.1</version>
</dependency>
Step 2: Define the ModelMapper bean in our Spring configuration
@SpringBootApplication
public class BlogApplication {
@Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}
public static void main(String[] args) {
SpringApplication.run(BlogApplication .class, args);
}
}
Step 3: Inject and use ModelMapper
private ObjectDto mapToDto(Object object ) {
ObjectDto objectDto = modelMapper.map(object ,ObjectDto.class);
return objectDto ;
}