Skip to content

Kotlin data classes and mapstruct #1672

@Pozo

Description

@Pozo

Related to #1298 and #782

A few months ago I came to the same conclusion with the all-open and the no-arg plugin like @thePhil and @nilotpal1981. However I really wanted to avoid using something like

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

Luckily since mapstruct 1.3.0.Beta2 it's possible to use builders for immutable classes. According to the documentation we can implement our custom builder provider logic. And the holiday season just came :) and I could create a proof of concept which is focusing on Kotlin's data classes.

So you can write down something like this:

@KotlinBuilder
data class Person(var firstName: String, var lastName: String, var phoneNumber: String, var birthdate: LocalDate)

The main idea is generating a builder for each data class and pass these builders to mapstruct via a custom BuilderProvider.

As I mentioned this is a proof of concept repository but I want to develop it further. If you think that this might be a way to use mapstruct with kotlin please share your idea or request and create an Issue here:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions