Java / MapStruct Java Interview questions part 2
What is the purpose of the uses attribute in @Mapper?
uses lets one mapper delegate mapping of certain nested types to other mapper classes, so logic isn't duplicated across mappers.
@Mapper(uses = { AddressMapper.class }) public interface PersonMapper { PersonDto toDto(Person person); }
If PersonDto has an AddressDto field, MapStruct looks at the listed helper mappers (and any default methods in the mapper itself) to find a method that converts Address to AddressDto, and calls it automatically instead of failing to map that nested property. You can list more than one helper class in uses, and MapStruct searches all of them for a suitable candidate method.
More Related questions...