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.
- You write Kotlin code instead of String references, allowing your IDE to support you with automatic refactorings and auto-complete.
- Fully designed with Kotlin in mind, making the code idiomatic and completely type-safe.
- Mappie is easy to use and infers as much as possible.
- Flawless compatibility with other platforms, such as Java types.
- Error messages are informative and suggest concrete actions.
Visit the project documentation for more in-depth information.
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}"
}
}
Mappie can be used via Gradle and Maven.
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.
Mappie can be used via Maven, it can be applied by adding the following snippet to your pom.xml
file.
...
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>...</version>
<configuration>
<compilerPlugins>
<compilerPlugin>mappie</compilerPlugin>
</compilerPlugins>
<pluginOptions>
...
</pluginOptions>
</configuration>
<dependencies>
<dependency>
<groupId>tech.mappie</groupId>
<artifactId>mappie-maven-plugin</artifactId>
<version>version</version>
</dependency>
</dependencies>
</plugin>
...
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.