
Annotation-driven compile-time code generation of type-safe, bidirectional conversion functions between similar data classes, producing zero-overhead mapping methods like .toOtherType() via an annotation processor.
A Kotlin Multiplatform library that automatically generates type-safe mapping/conversion code between similar data classes using KSP (Kotlin Symbol Processing).
This started as a fork of KConMapper but evolved into its own library, including multiplatform support.
MapKt enables you to define simple @MapKt annotations on source data classes and automatically
generates conversion functions like .toOtherType() without writing manual mapTo boilerplate
code.
Gradle (Kotlin):
// build.gradle.kts
plugins {
id("com.google.devtools.ksp") version "2.3.6"
}
dependencies {
val mapktVersion = "1.1.0" // or use latest
implementation("com.jakala.mapkt:mapkt-ksp:$mapktVersion")
ksp("com.jakala.mapkt:mapkt-ksp:$mapktVersion")
}Define two or more similar data classes with a shared mapping annotation:
@MapKt(
mapTo = [RemoteModel::class], // Map FROM Dog TO Cat
)
data class SharedModel(val name: String, val age: Int)
@MapKt(
mapTo = [SharedModel::class], // Map FROM Cat TO Dog
)
data class RemoteModel(val name: String, val age: Int)val shared = SharedModel("Fido", 5)
val remote = shared.toRemote()
println(remote.name) // Output: Fido
println(remote.age) // Output: 5
// Works in reverse!
val convertedDog = remote.toShared() Define mappings on data classes that should generate conversion functions.
/**
* Generates mapping functions from this class to the specified types.
*/
annotation class MapKt(
val mapTo: Array<KClass<*>> // Types this class maps TO
)mapkt-annotations/ # Annotation definitions (no dependencies)
mapkt-ksp/ # KSP processor that generates mapping code
sample/ # Sample project demonstrating usage
Look at the Provided Justfile, here, it contains tasks for building, testing, and publishing the library. You don't need to use Just, you can run the equivalent Gradle commands directly.
# Build and publish artifacts to your local Maven repo
./gradlew clean publishToMavenLocal
# Verify installation by building sample again
./gradlew :sample:buildReleases are published automatically to Maven Central via GitHub Actions.
build.gradle.kts.release version x.y.z
git tag v<version> and git push origin v<version>
A Kotlin Multiplatform library that automatically generates type-safe mapping/conversion code between similar data classes using KSP (Kotlin Symbol Processing).
This started as a fork of KConMapper but evolved into its own library, including multiplatform support.
MapKt enables you to define simple @MapKt annotations on source data classes and automatically
generates conversion functions like .toOtherType() without writing manual mapTo boilerplate
code.
Gradle (Kotlin):
// build.gradle.kts
plugins {
id("com.google.devtools.ksp") version "2.3.6"
}
dependencies {
val mapktVersion = "1.1.0" // or use latest
implementation("com.jakala.mapkt:mapkt-ksp:$mapktVersion")
ksp("com.jakala.mapkt:mapkt-ksp:$mapktVersion")
}Define two or more similar data classes with a shared mapping annotation:
@MapKt(
mapTo = [RemoteModel::class], // Map FROM Dog TO Cat
)
data class SharedModel(val name: String, val age: Int)
@MapKt(
mapTo = [SharedModel::class], // Map FROM Cat TO Dog
)
data class RemoteModel(val name: String, val age: Int)val shared = SharedModel("Fido", 5)
val remote = shared.toRemote()
println(remote.name) // Output: Fido
println(remote.age) // Output: 5
// Works in reverse!
val convertedDog = remote.toShared() Define mappings on data classes that should generate conversion functions.
/**
* Generates mapping functions from this class to the specified types.
*/
annotation class MapKt(
val mapTo: Array<KClass<*>> // Types this class maps TO
)mapkt-annotations/ # Annotation definitions (no dependencies)
mapkt-ksp/ # KSP processor that generates mapping code
sample/ # Sample project demonstrating usage
Look at the Provided Justfile, here, it contains tasks for building, testing, and publishing the library. You don't need to use Just, you can run the equivalent Gradle commands directly.
# Build and publish artifacts to your local Maven repo
./gradlew clean publishToMavenLocal
# Verify installation by building sample again
./gradlew :sample:buildReleases are published automatically to Maven Central via GitHub Actions.
build.gradle.kts.release version x.y.z
git tag v<version> and git push origin v<version>