1 min read

How to fix unknown property in result type - Mapstruct with Lombok

fix unknown property in result type, mapstruct with Lombok
How to fix unknown property in result type - Mapstruct with Lombok
mapstruct

Mapstruct is a great java tool for mapping properties of one type to another. It helps save time and prevent repetitive tasks. If you are not familiar with it, I suggest you check it out at the official website: https://mapstruct.org/

Fig 1. Compilation fail, due to mapstruct error

In Fig 1, notice that the complaint is about line 17. The error reads that it cannot find a "width" property in Card class. The Card class is shown in Fig 2. We can see that lombok is used, so there are no explicit getter methods. We also confirm that the "width" property is present in this class. Yet mapstruct says it cannot find it.

Fig 2. Card class with width property present

Why Mapstruct cannot find the property§

If we take a moment to look through the build.gradle file for this application, we might be able to see the cause of the error. In Fig 3, I had placed the mapstruct annotation processor before the lombok annotation processor. This means that at the time mapstruct is processing this class, it actually cannot find the getter property. So the error message is actually valid.

Fig 3. build.gradle for application

Solution§

Simply move the mapstruct annotation processor below that of lombok, and the problem goes away.

Happy Coding!!!