Mapping annotations for multiple source parameters

904 views
Skip to first unread message

Darren Reimer

unread,
Aug 31, 2015, 9:28:35 AM8/31/15
to mapstruct-users
I can see by section 3.3 of the documentation (Mapping methods with several source parameters) that you can map multiple source parameters to a single target, but I don't understand what mapping annotation you would use to specify this.  For the example method:
DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Address address);

...what mapping annotation would you use to result in the above method being called?  I would expect you would need something like the following (but this is not correct):
@Mapping(source = "{person,address}", target = "deliveryAddress")

Andreas Gudian

unread,
Aug 31, 2015, 1:50:40 PM8/31/15
to Darren Reimer, mapstruct-users
Hi Darren,

that's not possible, yet. But it'll come eventually. We have an issue in GitHub that roughly describes the same thing that you propose: https://github.com/mapstruct/mapstruct/issues/621

In the mean time, you can use something like this for the assignment of deliveryAddress:
@Mapping(target = "deliveryAddress", expression = "java( personAndAddressToDeliveryAddr( source.getPerson(), source.getAddress() )")

Hope that helps,
Andreas


--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-use...@googlegroups.com.
To post to this group, send email to mapstru...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Darren Reimer

unread,
Aug 31, 2015, 3:09:45 PM8/31/15
to mapstruct-users, ma...@darrenreimer.com
Okay thanks, Andreas.
I see how you could use an expression for this, but I ended up dealing with this in an @AfterMapping method on my top level object mapping for other reasons.
Thanks for your reply.
Reply all
Reply to author
Forward
0 new messages