
Mappie
Mappie is a Kotlin Multiplatform compiler plugin which generates code to simplify developing object mapping code. Writing object
mapping code is often a mind-numbing and error-prone task. Reducing this development effort will lead to a more
pleasant programming experience, and less risk of bugs.
Mappie offers the following advantages:
- All code is generated at compile-time, without the need for any reflection at runtime. Making the generated code
have the same runtime performance as if one would write the object mapping code manually.
Visit the project documentation for more in-depth information.
Example
The following snippet provides a minimal peek into the idiomatic style of Mappie. Suppose we have the data class Person
which we want to map to the data class PersonDto
data class Person(
val name: String,
val surname: String,
val age: Int,
)
data class PersonDto(
val name: String,
val age: Int,
)
We can achieve generating such a mapper using the following object mapper.
object PersonToPersonDtoMapper : ObjectMappie<Person, PersonDto>() {
override fun map(from: Person) = mapping {
to::name fromValue "${from.name} ${from.surname}"
}
}
Usage
Mappie can be used via Gradle and Maven.
Gradle
Mappie can be used via Gradle, it can be applied by adding the following snippet to your build.gradle.kts file.
plugins {
id("tech.mappie.plugin") version "version"
}
For more details, visit the gradle setup documentation.
Maven
Mappie can be used via Maven, it can be applied by adding the following snippet to your pom.xml file.
We must also add the mappie-api dependency. For example, for the JVM
<dependency>
<groupId>tech.mappie</groupId>
<artifactId>mappie-api-jvm</artifactId>
<version>version</version>
</dependency>
For more details, visit the maven setup documentation.