mapstruct-kotlin-builder

KotlinBuilder annotation for plugin for mapstruct

Лицензия

Лицензия

Категории

Категории

Kotlin Языки программирования MapStruct Универсальные библиотеки Bean Mapping
Группа

Группа

com.github.pozo
Идентификатор

Идентификатор

mapstruct-kotlin
Последняя версия

Последняя версия

1.4.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

mapstruct-kotlin-builder
KotlinBuilder annotation for plugin for mapstruct
Ссылка на сайт

Ссылка на сайт

https://github.com/Pozo/mapstruct-kotlin
Система контроля версий

Система контроля версий

https://github.com/Pozo/mapstruct-kotlin/tree/master

Скачать mapstruct-kotlin

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.pozo/mapstruct-kotlin/ -->
<dependency>
    <groupId>com.github.pozo</groupId>
    <artifactId>mapstruct-kotlin</artifactId>
    <version>1.4.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.pozo/mapstruct-kotlin/
implementation 'com.github.pozo:mapstruct-kotlin:1.4.0.0'
// https://jarcasting.com/artifacts/com.github.pozo/mapstruct-kotlin/
implementation ("com.github.pozo:mapstruct-kotlin:1.4.0.0")
'com.github.pozo:mapstruct-kotlin:jar:1.4.0.0'
<dependency org="com.github.pozo" name="mapstruct-kotlin" rev="1.4.0.0">
  <artifact name="mapstruct-kotlin" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.pozo', module='mapstruct-kotlin', version='1.4.0.0')
)
libraryDependencies += "com.github.pozo" % "mapstruct-kotlin" % "1.4.0.0"
[com.github.pozo/mapstruct-kotlin "1.4.0.0"]

Зависимости

runtime (1)

Идентификатор библиотеки Тип Версия
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.3.72

Модули Проекта

Данный проект не имеет модулей.

mapstruct-kotlin

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 - pozo@gmx.com

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

Версии библиотеки

Версия
1.4.0.0
1.3.1.2
1.3.1.1
1.3.1.0