I have a following java bean in my application
public class Status{
private String statusType;
private String status;
private String statusCode;
//getters and setters
}
public class Associate{
private String name;
private String id;
private List<Status> statuses;
//getters & setters
}
And possible values for Status.statusTypes are {"O", "P", "R", "S", "A"}. Now I need to map statuses as part of Associate mapper but mapping should only return status and statusType if statusType matches any of {"O", "A", "P"} ?
As of now I'm doing custom default method in mapper like below
public AssociateMapper{
Predicate<Status> status = (sts) -> null != sts &&null!=sts.getStatusType
&& "O|A|P".contains(sts.getStatusType());
@Mappings({
//some mappings
@Mapping(target = "statuses", expression = "java(associate.getStatuses().stream().filter(status).collect(Collectors.toList()))" )
})
Associate mapAssociate(Associate associate);
}
Is there any elegant way than this using mapStruct config itself?