Skip to content

A KSP annotation processor for boilerplate-free mapping of data, enum, and sealed classes in Kotlin Multiplatform projects

License

Notifications You must be signed in to change notification settings

jacksever/kotlin-automapper

Repository files navigation

Kotlin AutoMapper

License Maven Central Kotlin Multiplatform Kotlin KSP

Effortless, type-safe object-to-object mapping in Kotlin. Tired of writing boilerplate code to convert one object to another? This library does it for you at compile time, with full support for Kotlin Multiplatform.

Kotlin AutoMapper uses KSP (Kotlin Symbol Processing) to generate extension functions that automatically map your data, enum, and sealed classes. No reflection, no runtime magic - just pure, fast, and safe generated code for all your targets.

➡️ View the full documentation for Setup, How to Use, and Advanced Usage ⬅️

Features

  • Kotlin Multiplatform First: Works seamlessly across JVM, iOS, JS, Wasm, and other Kotlin targets.
  • Type-Safe & Compile-Time Verified: All mappings are generated and validated by KSP at compile time. No reflection, no runtime errors.
  • Zero Runtime Dependencies: The annotation library is SOURCE-only and adds no overhead to your production app.
  • Broad Class Support: Out-of-the-box support for data, enum, and sealed classes, including complex nested hierarchies.
  • Powerful Mapping Customization:
    • Property Renaming: Easily map properties with different names using @PropertyMapping.
    • Default Values: Provide fallback values for missing or null properties with @DefaultValue.
  • Advanced Type Conversion:
    • Custom Converters: Define your own conversion logic for complex types (like Uuid or Instant) using @AutoConverter.
    • Automatic Primitive Conversion: Handles conversions between primitives like Int, Long, String automatically.
  • Smart & Safe Generation:
    • Bidirectional Mapping: Generate forward and reverse mappings with a single reversible = true flag.
    • Visibility Control: Generated code automatically inherits the visibility (public or internal) of your @AutoMapperModule.
    • @OptIn Propagation: Automatically propagates @OptIn annotations from your custom converters to the generated functions, ensuring compile-time safety for experimental APIs.

License

This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.