Reputation: 43
I have an object that looks like this:
public class Aggregator {
private Header header;
private Second second;
}
And I want to map from Aggregator to Header but I can't use void methods Mapstruct version is 1.3
How can I achieve that goal?
Edit:
I'm trying to map the business entity "Aggregator" to the DTO entity "HeaderDTO"
I'm trying to achieve that by creating an abstract class with the annotation: @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) and the method: "public abstract HeaderDTO toDTO(Aggregator aggregator);"
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public abstract class AggregatorMapper {
public abstract HeaderDTO toDTO(Aggregator aggregator);
}
Upvotes: 2
Views: 669
Reputation: 21423
MapStruct allows you to map the entire target object to a particular source reference.
e.g.
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public abstract class AggregatorMapper {
@Mapping(target = ".", source = "header"
public abstract HeaderDTO toDTO(Aggregator aggregator);
}
Upvotes: 1