My goal was to check the existence of a value, and give it to an attribute, if it exists, or something else if it doesn’t.
I was reading the MapStruct documentation in search for a solution that would benefit me. I stumbled about the @BeforeMapping and @MappingTarget annotations, and even could get some examples from the documentation itself.
So I tried for myself with a method similar to the following one:
@BeforeMapping
default void beforeMappingToModel(@MappingTarget MyModel myModel, MyDto myDto) {
if(null == myDto.getFirstName()) {
myModel.setFistName(myDto.getFullName);
}
}
When I tried implementing such a method, it doesn’t get implemented to my mapping method during the generation of the implementation file.
If I remove the @MappingTarget annotation, the @BeforeMapping does work and I can see the method implemented after the generation, although it’s no longer of use in my case.
Any ideas ?