Map multiple source fields to same type target fields with Mapstruct
<p>Consider the following POJOs:</p>

<pre><code>public class SchedulePayload {
    public String name;
    public String scheduler;
    public PeriodPayload notificationPeriod;
    public PeriodPayload schedulePeriod;
}

private class Lecture {
    public ZonedDateTime start;
    public ZonedDateTime end;
}

public class XmlSchedule {
    public String scheduleName;
    public String schedulerName;
    public DateTime notificationFrom;
    public DateTime notificationTo;
    public DateTime scheduleFrom;
    public DateTime scheduleTo;
}

public class PeriodPayload {
    public DateTime start;
    public DateTime finish;
}
</code></pre>

<p>Using MapStruct, I created a mapper that maps <code>XmlSchedule</code> to a <code>SchedulePayload</code>. Due to "business" "logic", I need to constrain <code>notificationPeriod</code> and <code>schedulePeriod</code> to a <code>Lecture</code>'s <code>start</code> and <code>end</code> field values. Here is what I've come up to, using another class:</p>

<pre><code>@Mapper(imports = { NotificationPeriodHelper.class })
public interface ISchedulePayloadMapper
{
    @Mappings({
        @Mapping(target = "name", source = "scheduleName"),
        @Mapping(target = "scheduler", source = "schedulerName"),
        @Mapping(target = "notificationPeriod", expression = "java(NotificationPeriodHelper.getConstrainedPeriod(xmlSchedule, notificationFrom, notificationTo))"),
        @Mapping(target = "schedulePeriod", expression = "java(NotificationPeriodHelper.getConstrainedPeriod(xmlSchedule, scheduleFrom, scheduleTo))")
    })
    SchedulePayload map(XmlSchedule xmlSchedule, Lecture lecture);

}
</code></pre>

<p>Is there any way this can be achieved in another way (i.e. another mapper, decorators, etc.)? How can I pass multiple values (xmlSchedule, lecture) to a mapper?</p>