Mapping using target constructor - #2074
Conversation
sjaakd
left a comment
There was a problem hiding this comment.
Hey Filip,
What a work 💯 ! I went through your PR. Loads of test 👍
Some of the things we should discuss:
- opt-out
- mixed scenarios (half constructor, half setters)
- name base mapping (I think its there, but doc needs update).
- what if you don't have control over the target?
testcases are really plentiful. I'll ponder on it a bit more.
|
Thanks a lot for the review @sjaakd. Regarding your questions:
In theory adding a public empty constructor would make MapStruct use that one. If there is an
There are no tests for that, but it would work. Although if you have the same property in a constructor and a setter then the one from the constructor would be used. Will add tests for that as well.
Nice spot, will add that.
Well you still have the option to add an |
|
@sjaakd I added a new commit and applied your feedback on it. Let me know what you think |
sjaakd
left a comment
There was a problem hiding this comment.
some documentation nagging :)
|
I've added more commits:
|
…iating mapping targets By default the constructor argument names are used to extract the target properties. If a constructor is annotated with an annotation named `@ConstructorProperties` (from any package) then it would be used to extract the target properties. If a mapping target has a parameterless empty constructor it would be used to instantiate the target. When there are multiple constructors then an annotation named `@Default` (from any package) can be used to mark a constructor that should be used by default when instantiating the target. Supports mapping into Java 14 Records and Kotlin data classes out of the box
Fixes #73.
It would be good to get some feedback on it.