Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No import is added to generated class when using '@BeforeMapping' on a 'used' mapper #2807

Closed
1 task done
prgood opened this issue Apr 4, 2022 · 2 comments · Fixed by #2808
Closed
1 task done
Labels
Milestone

Comments

@prgood
Copy link

prgood commented Apr 4, 2022

If we use a "baseMapper" class that the only method called is a "@BeforeMapping", than a implementation class is generated without the proper import. This issue was tested at versions: "1.4.2.final" and "1.5.0.RC1"

If we use any of regular(no "BeforeMapping") methods from baseMapper the important is added to the generated class.

public class BaseMapper {
    private BaseMapper() {   }

    public static String mapUuidToString(UUID uuid) {
        return uuid == null ? null : uuid.toString();
    }

    @BeforeMapping
    public static <T, D> List<D> handleNullLists(Iterable<T> source) {
        return source == null ? new ArrayList() : null;
    }
}

The code below generates a no working implementation class, since a import to BaseMapper is missing:

@Mapper(componentModel = "spring", uses = {BaseMapper.class})
public interface NoWorkingSample {

    List<String> map(List<Integer> list);
}

The code below generates a working implementation class, since we are also using the mapUuidToString method from the BaseMapper:

@Mapper(componentModel = "spring", uses = {BaseMapper.class})
public interface WorkingSample {

    List<String> map(List<UUID> list);
}
  • Is this an issue (and hence not a question)?
Zegveld pushed a commit to Zegveld/mapstruct that referenced this issue Apr 4, 2022
@Zegveld
Copy link
Contributor

Zegveld commented Apr 4, 2022

Thank you for the bug report.
After looking into this I noticed it only surfaces when also using the "spring" componentModel.
PR is on the way to get this fixed.

@prgood
Copy link
Author

prgood commented Apr 5, 2022

Thanks for quick reponse. You guys are amazing! :-)

I didn't notice that "spring" componentModel was required to trigger this, thanks for the analysis.

Zegveld added a commit that referenced this issue Apr 8, 2022
#2808)

Co-authored-by: Ben Zegveld <Ben.Zegveld@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants