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

Introduce @Mapper(maxDepth = 2) #3547

Open
stankay opened this issue Mar 5, 2024 · 1 comment
Open

Introduce @Mapper(maxDepth = 2) #3547

stankay opened this issue Mar 5, 2024 · 1 comment

Comments

@stankay
Copy link

stankay commented Mar 5, 2024

Use case

When mapping JPA entities that contain bi-directional relations into DTOs, the mapper gets stuck in StackOverflow error for obvious reason. One must manually handle those mappings using available means, such as @Mapper(uses = ...) and @Mapping(qualifiedByName = ...), but in certain scenarios, it's a significant amount of work.

Generated Code

My suggestion is to introduce new method Integer maxDepth() into the @Mapper annotation, which would stop the recursive generation of mapping code after N recursions. This is sufficient to transfer entity and entities contained @manytoone, @OneToMany, @manytomany relations but not deeper.

Possible workarounds

No response

MapStruct Version

No response

@filiphr
Copy link
Member

filiphr commented Mar 10, 2024

I am not sure that this is something that we can do. How would this work when you have separate mappers for the parent and child?

In my opinion this is something that should be fixed on the defining mapper side. You can define a custom mapping method that can then be used to ignore the second level of the mapping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants