All Projects → Pozo → Mapstruct Kotlin

Pozo / Mapstruct Kotlin

Licence: mit
Using mapstruct with kotlin data classes.

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to Mapstruct Kotlin

smartstruct
Dart Code Generator for generating mapper classes
Stars: ✭ 20 (-76.19%)
Mutual labels:  mapper, annotation-processor
Dart
Extras binding and intent builders for Android apps.
Stars: ✭ 1,203 (+1332.14%)
Mutual labels:  annotation-processor
Hamcrest Pojo Matcher Generator
Autogenerated java hamcrest matchers for pojo with help of AnnotationProcessor
Stars: ✭ 31 (-63.1%)
Mutual labels:  annotation-processor
Kpoet
An expressive DSL built on top of JavaPoet to make writing code almost as easy as writing the code yourself.
Stars: ✭ 58 (-30.95%)
Mutual labels:  annotation-processor
Metasra Pipeline
MetaSRA: normalized sample-specific metadata for the Sequence Read Archive
Stars: ✭ 33 (-60.71%)
Mutual labels:  annotation-processor
Kotlin Builder Annotation
A minimal viable replacement for the Lombok @Builder plugin for Kotlin code
Stars: ✭ 67 (-20.24%)
Mutual labels:  annotation-processor
Showkase
🔦 Showkase is an annotation-processor based Android library that helps you organize, discover, search and visualize Jetpack Compose UI elements
Stars: ✭ 873 (+939.29%)
Mutual labels:  annotation-processor
Genesis
Spring cloud Example
Stars: ✭ 83 (-1.19%)
Mutual labels:  mapper
Spring Boot Api Project Seed
🌱🚀一个基于Spring Boot & MyBatis的种子项目,用于快速构建中小型API、RESTful API项目~
Stars: ✭ 8,979 (+10589.29%)
Mutual labels:  mapper
Auto Value Map
AutoValue Extension to add Map generation support
Stars: ✭ 56 (-33.33%)
Mutual labels:  annotation-processor
Gsonpath
A Java annotation processor library which generates gson type adapters using basic JsonPath style annotations
Stars: ✭ 54 (-35.71%)
Mutual labels:  annotation-processor
Mezzanine
An annotation processor that reads files at compile time
Stars: ✭ 45 (-46.43%)
Mutual labels:  annotation-processor
Gencycler
Gencycler is the fastest way to write RecyclerView adapters
Stars: ✭ 73 (-13.1%)
Mutual labels:  annotation-processor
Change By Example
Finds a function that transforms a given object into another given object.
Stars: ✭ 32 (-61.9%)
Mutual labels:  mapper
Repodb
A hybrid ORM library for .NET.
Stars: ✭ 1,223 (+1355.95%)
Mutual labels:  mapper
Koloboke
Java Collections till the last breadcrumb of memory and performance
Stars: ✭ 909 (+982.14%)
Mutual labels:  annotation-processor
Jenny
JNI glue code generator
Stars: ✭ 53 (-36.9%)
Mutual labels:  annotation-processor
Inspector
A tiny class validation library.
Stars: ✭ 64 (-23.81%)
Mutual labels:  annotation-processor
Ourbatis
Enhancement tools that make the development of Mybatis easier.
Stars: ✭ 84 (+0%)
Mutual labels:  mapper
Mapper
🌍 Transforms arrays using an object composition DSL.
Stars: ✭ 81 (-3.57%)
Mutual labels:  mapper

mapstruct-kotlin

⚠️ Since 1.4 MapStruct has support for using constructor arguments when instantiating mapping targets. This also works with Kotlin data classes.

Since mapstruct 1.3.0.Beta2 it's possible to use builders for immutable classes. According to the documentation you can implement your custom builder provider logic. This project take advantage of this and provide a custom BuilderProvider for kotlin data classes.

So instead of this (source)

data class PersonDto(var firstName: String?, var lastName: String?, var phone: String?, var birthdate: LocalDate?) {
    // Necessary for MapStruct
    constructor() : this(null, null, null, null)
} 

We can do this

@KotlinBuilder
data class PersonDto(val firstName: String, val lastName: String, val phone: String, val birthdate: LocalDate)

With a mapper

@Mapper
interface PersonMapper {
    fun map(person: Person): PersonDto
}

Usage

First apply kapt plugin

apply plugin: 'kotlin-kapt'

Then add these to your project as dependency

api("com.github.pozo:mapstruct-kotlin:1.3.1.2")
kapt("com.github.pozo:mapstruct-kotlin-processor:1.3.1.2")

Check out the directory example for a basic usage example.

Versioning

For example in case of 1.3.1.1 the first part 1.3.1 is the mapstruct version number and the last digit 1 reserved for future patches.

Project structure

  • mapstruct-kotlin-builder contains only the KotlinBuilder annotation
  • mapstruct-kotlin-processor responsible for generating the builders for the kotlin data classes with the help of a custom DefaultBuilderProvider
  • example responsible for demonstrating this library usage

Build and run the example application

./gradlew -p example clean build

TODO

  • Map with custom types are not working
  • Look over kotlin-builder-annotation project and replace with class generating module (builder-processor)
  • Writing tests
  • Versioning and release process

Licensing

Please see LICENSE file

Contact

Zoltan Polgar - [email protected]

Please do not hesitate to contact me if you have any further questions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].