Dozer hint to MapStruct ?

178 views
Skip to first unread message

Rob Dog

unread,
Oct 12, 2016, 5:10:56 PM10/12/16
to mapstruct-users

Using Hints for Collection Mapping


6. Mapping collections

So given the links above, I'm not sure that there is an equivalent way to map collections in MapStruct, please advise me.

Case in point:

   <mapping> 
   <class-a >com.nirvana.PatientMedicationAdherence</class-a>
   <class-b>com.nirvana.PatientAdherence</class-b> 
    <field>
        <a>medicationAdherence</a>
        <b>medicationAdherenceList</b>
        <a-hint>com.nirvana.MedicationAdherence</a-hint>
        <b-hint>com.nirvana.core.MedicationAdherence</b-hint>
   </field>
   </mapping>

In the example above, the type in the list is a base class or interface for the classes specified in the mapping (class-a and class-b).


@Mapper
public interface NirvanaMapper {

    List<com.nirvana.core.MedicationAdherence> MedAdhereToCoreMedAdhereList(List<com.nirvana.MedicationAdherence> elements);
    List<PatientAdherence> patientMedicationAdherencesToPatientAdherences(List<PatientMedicationAdherence> patientMedicationAdherences);
PatientAdherence patientMedicationAdherenceToPatientAdherence(PatientMedicationAdherences patientMedicationAdherence);
}



Does this seem the correct mapper, or am I completely misunderstanding this?

Andreas Gudian

unread,
Oct 13, 2016, 2:21:11 AM10/13/16
to Rob Dog, mapstruct-users
You'll probably need to declare another method to map the single MedicationAdherence beans.

If one of your target bean types is an interface/abstract class, the you could define a factory method to provide a new instance of the target type.

If there are multiple possibilities, you might want to follow the pattern described in this issue: 

--
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.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages