mapping multiple sources to one target list

4,174 views
Skip to first unread message

declan roche

unread,
Jul 24, 2017, 11:25:19 AM7/24/17
to mapstruct-users

Hi

 

I have a target property which is a list of typeZ and have a property which is a list of typeA.

Using a defined mapper (listA2listZmapper) I can map my listA to listZ.

 

I would like to add another source property which is also  list of typeA

Which would also use the same mapper and append to the list

 

 

@Mapping(target = "ListOfTypeZ", source = "entity1.ListOfTypeA"),

@Mapping(target = "ListOfTypeZ ", source = " entity2.ListOfTypeA"),

 

 

But I am getting an error (as below) saying I can only map a target property once.

Is there a work around for this ?

 

 

:generateMainMapperClassesCxxx.java:72: error: Target property " ListOfTypeZ " must not be mapped more than once.

              

Filip Hrisafov

unread,
Jul 27, 2017, 2:31:22 AM7/27/17
to mapstruct-users
Hi,

The only way to combine two parameters into single target is by using expression. Something like this StackOverflow question.

Cheers,
Filip
Reply all
Reply to author
Forward
0 new messages