Skip to content

#3960 Ignore deprecated constructors when selecting a constructor - #4127

Open
obabichevjb wants to merge 1 commit into
mapstruct:mainfrom
obabichevjb:obabichev/issue-3960-mapstruct-kotlin-2-3-0
Open

obabichevjb wants to merge 1 commit into
mapstruct:mainfrom
obabichevjb:obabichev/issue-3960-mapstruct-kotlin-2-3-0

Conversation

@obabichevjb

Copy link
Copy Markdown

Here is the fix of the issue Mapstruct not working with Kotlin/Kapt 2.3.0-RC #3960

The main part of the fix - ignoring of deprecated constructors (which could be created by plugin.jpa for example).

plugin.jpa adds a hidden no-arg constructor, because JPA requires one. Until Kotlin 2.3.0 a bug (KT-53122)
left that constructor out of the KAPT stubs, so MapStruct never saw it. Kotlin 2.3.0 fixed the bug — and now MapStruct
sees two constructors: @Deprecated public MyClass () { } generated for JPA and public MyClass (String id, String name, String password) the real one.

MapStruct's rule was "if a parameterless constructor exists, use it and ignore the others." So it picked the generated
one, then tried to fill the object with setters — of which there are none. Result: nothing could be written.

The fix allows to ignore generated constructor. Which is marked deprecated in Kotlin @Deprecated (level = HIDDEN).

Two safety valves: if every constructor is deprecated they're all kept (otherwise the type couldn't be built at all),
and an explicit @Default still wins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant