Building Spring Boot Rest Web Services might become cumbersome, especially when domain model objects need to be converted in many different DTOs (Data Transfer Object) and vice versa. Writing mapping manually is boring and involves boilerplate code. Is it possible to avoid it?

Yes, it is! Thanks to MapStructMapStruct is a Java annotation processor for the generation of type-safe and performant mappers for Java bean classes.

Integrating MapStruct with Spring Boot in Java is well documented (Automating Code with MapStruct), but what if we wanted to use** Kotlin**?

Let’s see how can MapStruct be integrated into a Spring Boot and Kotlin project.

1. Gradle dependency

Let’s add the Kapt compiler plugin and the MapStruct processor dependencies in build.gradle.kts.

plugins {
   kotlin("kapt") version "1.3.72"
}

dependencies {   
   kapt("org.mapstruct:mapstruct-processor:1.3.1.Final")
}

#dto #kotlin #spring-boot #mapstruct

Avoiding Boilerplate Code With MapStruct, Spring Boot and Kotlin
27.80 GEEK