Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 26, 2020. It is now read-only.
/mapstruct-kotlinPublic archive

Using mapstruct with kotlin data classes.

License

NotificationsYou must be signed in to change notification settings

Pozo/mapstruct-kotlin

Repository files navigation

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

Since mapstruct1.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 customBuilderProvider for kotlin data classes.

So instead of this (source)

data classPersonDto(varfirstName:String?,varlastName:String?,varphone:String?,varbirthdate:LocalDate?) {// Necessary for MapStructconstructor():this(null,null,null,null)}

We can do this

@KotlinBuilderdata classPersonDto(valfirstName:String,vallastName:String,valphone:String,valbirthdate:LocalDate)

With a mapper

@MapperinterfacePersonMapper {funmap(person:Person):PersonDto}

Usage

First apply kapt plugin

applyplugin:'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 directoryexample for a basic usage example.

Versioning

For example in case of1.3.1.1 the first part1.3.1 is the mapstruct version number and the last digit1 reserved for future patches.

Project structure

  • mapstruct-kotlin-builder contains only theKotlinBuilder annotation
  • mapstruct-kotlin-processor responsible for generating the builders for the kotlin data classes with the help of a customDefaultBuilderProvider
  • 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 overkotlin-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 -pozo@gmx.com

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

About

Using mapstruct with kotlin data classes.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp