Reputation: 144
So in the example below, I have 2 inputs object, being mapped to one output object. The majority of the mappings are direct from one input, to one output, with only one coming from another object.
@Mapping(source = "input.a" target = "output.a")
@Mapping(source = "input.b" target = "output.b")
@Mapping(source = "input.c" target = "output.c")
@Mapping(source = "input.d" target = "output.d")
@Mapping(source = "extra.a" target = "output.extraa")
Output toOutputMapper(Input input, ExtraValues extra)
Is there a way to say "use this object as default", which saves me mapping the values and forgoing the automatic mapping Mapstruct provides?
Something like:
@Mapping(source = "extra.a" target = "output.extraa")
Output toOutputMapper(@Default Input input, ExtraValues extra)
Upvotes: 0
Views: 268
Reputation: 21403
When using MapStruct 1.4 you can use mapping to current target to achieve what you are looking for.
e.g.
@Mapping(source = "input" target = ".")
@Mapping(source = "extra.a" target = "output.extraa")
Output toOutputMapper(Input input, ExtraValues extra)
Upvotes: 1