Java / MapStruct Java Interview questions part 2
How does MapStruct integrate with Lombok, and what issues can occur?
MapStruct reads property information from generated getters and setters, so when a source or target class uses Lombok annotations like @Getter/@Setter or @Data, MapStruct needs to see those Lombok-generated methods to build its mapping code correctly.
The issue is one of annotation processor ordering: if MapStruct's processor runs before Lombok's during the same compilation round, it sees the class before Lombok has added the getters/setters, and the mapper ends up with "unmapped target property" warnings for fields that actually exist.
<annotationProcessorPaths> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </path> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok-mapstruct-binding</artifactId> </path> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> </path> </annotationProcessorPaths>
Adding lombok-mapstruct-binding to the annotation processor path fixes the ordering so Lombok's generated methods are visible to MapStruct during the same compilation round.
More Related questions...