0
votes

I have a list of 1.Address object with ID,Street name,City and PostalCode and a list of 2.Contact object with ID, Street,City and Phone.

Can i copy Street name and City alone from List of Contact to List of Address based on ID matching ?

Address Object already has ID and Postalcode populated. Contact Object already has ID and Street and City populated.

1

1 Answers

0
votes

No you can't. MapStruct does not do conditional mapping. This is typically a business problem for which it is hard to predict what the user actually wants. You'll have to write a (default) method implementation or create a used mapper. On the bright side: if MapStruct recognizes the method signature at other call sites, it will select the handwritten method. See here for more info.