I am using MapStruct to bind objects from my LibraryResponse
class to my APIResponse
class, but I am getting compile warnings that the target properties withVar1
, withVar2
, … withVar20
are unmapped. My APIResponse
class has a builder class with setter methods for the above variables, but I don’t want to manually map each variable with a @Mapping
annotation. Is there a way to tell MapStruct to use the getters instead of the builder class?
Yes, you can tell MapStruct to use the getters instead of the builder class by adding componentModel = "spring"
to your @Mapper
annotation. This will make MapStruct use the getters instead of the builder class to set the properties in your target object.
Here is an example:
@Mapper(componentModel = "spring")
public interface MyMapper {
APIResponse map(LibraryResponse libraryResponse);
}