I want to map the following classes
class Schedule {
ZoneId timezoneId;
List<AvailabilityRule> rules;
}
class AvailabilityRule {
long startEpoch;
long endEpoch;
}
to these classes.
class ScheduleDTO {
String timezone;
List<AvailabilityRuleDTO> rules;
}
class AvailabilityRuleDTO {
ZonedDateTime startTime;
ZonedDateTime endTime;
}
Both timezoneId and startEpoch are needed for calculating startTime.
Instant instant = Instant.ofEpochMilli(startEpoch);
ZonedDateTime zonedDateTime = instant.atZone(timezoneId);
How can I achieve this using mapstruct?
Pseudo code of what I want
@Mapping(source = {"startEpoch", "timezoneId"}, target = "startTime", qualifiedByName = "epochToString")
AvailabilityRuleDTO toAvailabilityRuleDTO(AvailabilityRule
availabilityRule, Schedule schedule);