Map Target with multiple sources inside main dto mapping

3,581 views
Skip to first unread message

Gerrit Brehmer

unread,
Aug 11, 2015, 11:16:04 AM8/11/15
to mapstruct-users
I need the possibility to define multiple sources for target mapping like it is possible in a single mapping rule. Or how can I achieve this mapping? The second map-Method should be automatically used by the first map-method, because ClassC can be constructed by ClassD & ClassE, which both are part of ClassA object hierarchy.

    @Mappings({
            @Mapping(source = ["inner.prop.d","inner.prop.e"], target = "c") })
    ClassA map(ClassB b);

    // ClassC contains props from ClassD & ClassE
    ClassC map(ClassD d, ClassE e);


Gerrit Brehmer

unread,
Aug 11, 2015, 11:31:47 AM8/11/15
to mapstruct-users

Sorry ClassD & ClassE are part of Input ClassB object

--
You received this message because you are subscribed to a topic in the Google Groups "mapstruct-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapstruct-users/1mNf7Ik0mL0/unsubscribe.
To unsubscribe from this group and all its topics, 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.

Andreas Gudian

unread,
Aug 11, 2015, 2:25:10 PM8/11/15
to Gerrit Brehmer, mapstruct-users
Hi Gerrit,

looks interesting! We had something related to this in mind already, tracked in https://github.com/mapstruct/mapstruct/issues/73 (for making use of one or more constructor-args).
I could imagine that whatever we come up there with would have some links to the feature you describe.

Could you maybe open an issue for this on github? And maybe reference #73...

Thanks,
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.

Gunnar Morling

unread,
Aug 12, 2015, 2:28:13 AM8/12/15
to mapstruct-users, gerrit....@gmail.com
Hi,

For the time being, Java expressions may be a solution for you, see http://mapstruct.org/documentation/#section-expressions.

Cheers,

--Gunnar


On Tuesday, August 11, 2015 at 8:25:10 PM UTC+2, Andreas Gudian wrote:
Hi Gerrit,

looks interesting! We had something related to this in mind already, tracked in https://github.com/mapstruct/mapstruct/issues/73 (for making use of one or more constructor-args).
I could imagine that whatever we come up there with would have some links to the feature you describe.

Could you maybe open an issue for this on github? And maybe reference #73...

Thanks,
Andreas
2015-08-11 17:31 GMT+02:00 Gerrit Brehmer <g...r@gmail.com>:

Sorry ClassD & ClassE are part of Input ClassB object

Am 11.08.2015 17:16 schrieb "Gerrit Brehmer" <g...r@gmail.com>:
I need the possibility to define multiple sources for target mapping like it is possible in a single mapping rule. Or how can I achieve this mapping? The second map-Method should be automatically used by the first map-method, because ClassC can be constructed by ClassD & ClassE, which both are part of ClassA object hierarchy.

    @Mappings({
            @Mapping(source = ["inner.prop.d","inner.prop.e"], target = "c") })
    ClassA map(ClassB b);

    // ClassC contains props from ClassD & ClassE
    ClassC map(ClassD d, ClassE e);


--
You received this message because you are subscribed to a topic in the Google Groups "mapstruct-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapstruct-users/1mNf7Ik0mL0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapstruct-users+unsubscribe@googlegroups.com.
To post to this group, send email to mapstruct-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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-users+unsubscribe@googlegroups.com.
To post to this group, send email to mapstruct-users@googlegroups.com.

Gerrit Brehmer

unread,
Aug 12, 2015, 3:16:04 AM8/12/15
to mapstruct-users, gerrit....@gmail.com
Am Dienstag, 11. August 2015 20:25:10 UTC+2 schrieb Andreas Gudian:
looks interesting! We had something related to this in mind already, tracked in https://github.com/mapstruct/mapstruct/issues/73 (for making use of one or more constructor-args).
I could imagine that whatever we come up there with would have some links to the feature you describe.

Could you maybe open an issue for this on github? And maybe reference #73...

I will open an issue this evening, no problem. 

Gerrit Brehmer

unread,
Aug 12, 2015, 3:20:58 AM8/12/15
to mapstruct-users, gerrit....@gmail.com
Am Mittwoch, 12. August 2015 08:28:13 UTC+2 schrieb Gunnar Morling:
For the time being, Java expressions may be a solution for you, see http://mapstruct.org/documentation/#section-expressions.

Thanks, code is a little bit long, because null checks muss be added manually, but I have not to add new properties if something was changed. Other workaround I was thinking about is to use single source mapping method (enclosing class - 'inner.prop' - instead of ClassD & ClassE props directly) and to map fields manually.
Reply all
Reply to author
Forward
0 new messages