@MAPSTRUCT. No property named “packaging” exists in source parameter(s)

For those, who have the same issue when using mapstruct + lombok: I had the same issue. The reason was that I’ve been using Lombok plugin too. There’s no need to remove it, but you have to ensure that in pom.xml in <annotationProcessorPaths> Lombok tag is before the Mapstruct one. Example (part of pom.xml file): … Read more

MapStruct – @Mapper annotation don’t create bean

I resolved the error by doing mvn clean install Also add this to your pom <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <source>1.8</source> <target>1.8</target> <annotationProcessorPaths> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </path> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${org.mapstruct.version}</version> </path> </annotationProcessorPaths> <compilerArgs> <compilerArg> -Amapstruct.defaultComponentModel=spring </compilerArg> </compilerArgs> </configuration> </plugin>

MapStruct + Lombok together not compiling: unknown property in result type

The reason why it does not work is because Maven only uses the MapStruct processor and not the Lombok one. The annotationProcessorPaths tells maven which processors it should use. The delombok does nothing as you are ending up with 2 files per class and I think that the maven compiler does not see them. You … Read more

How to write Junit test for mapstruct abstract mapper injected via Spring

In response to @Richard Lewan comment here is how I declared my test class for the abstract class ConfigurationMapper using 2 subMappers @RunWith(SpringRunner.class) @SpringBootTest(classes = {ConfigurationMapperImpl.class, SubMapper1Impl.class, SubMapper2Impl.class}) public class ConfigurationMapperTest { You use the Impl generated classes in the SpringBootTest annotation and then inject the class you want to test: @Autowired private ConfigurationMapper configurationMapper; … Read more

Map custom method mapper to Mapstruct

As you have multiple default methods that return the same type. You would need to use Mapping method selection based on qualifiers. What this means is that you would need to write your mapper in the following format: @Mapper public interface ItemMapper { // Omitting other mappings for clarity @Mapping(source = “item”, target = “locationDto”, … Read more

Mapstruct – How can I inject a spring dependency in the Generated Mapper class

As commented by brettanomyces, the service won’t be injected if it is not used in mapping operations other than expressions. The only way I found to this is : Transform my mapper interface into an abstract class Inject the service in the abstract class Make it protected so the “implementation” of the abstract class has … Read more

Java mapping: Selma vs MapStruct [closed]

(Original author of Selma so slight different point of view) Selma and MapStruct does the same job with some differences. First it appears that Selma generated code is just a bit faster than MapStruct (http://javaetmoi.com/wp-content/uploads/2015/09/2015-09-mapping-objet-objet2.png). The 0.13 release number does not really reflects the maturity of code Selma is stable and robust it is in … Read more

tech