-
-
Notifications
You must be signed in to change notification settings - Fork 946
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
IMPROVEMENT: Discover existing mappers instead of providing "Mapper.uses" class array #1509
Comments
This is an interesting proposal. We would need to make sure that the mapper itself doesn't get detected. However, apart from that it should be fine. Will you expect to find mappers in sub packages as well? Or only in a single one? |
Should every class be detected as a possible mapper? In this case the annotation should be used with caution and thus only if the package just contains "real" mappers. To prevent issues in case every class will be seen as a possible mapper I would propose to just search in the defined package and not in sub-packages. OR: Allow something like an "ant-path" syntax ( |
I'm not entirely sure what this brings.
In my experience, I use typically less than 5 mappers. I want to have control over what mapstruct considers as mapper, since there can be a lot on your class path. I also tend to separate forward from reverse mappings, having a shared config for the mappings. Don't want to accidentally mix up those..
|
First of all THANK YOU! All of you for coming up with this library. It is easy to use and very intuitive. I use mappers in conjunction with JAXB and we have 4 different enterprise schemas to map (86 mappers). We could use less, but why repeat the code ??? Benefits:
Example: Mapped type class was modified to include new attribute that is already has a mapper. Unless code inspection is performed the possible re-use will not be discovered.
|
Thanks for the feedback. Appreciate that.
You mean, classes annotated with
That's tricky, right..? You'll never know if the last method it finds is the correct one. But in essence, in case there are multiple qualifying methods you would issue a warning in stead of an error (as is the case now)? Note we have Just out of curiosity: we have the concept of |
I use MapperConfig. It is very useful (especially for unmappedTargetPolicy). But it doesn't provide support for example scenario I outlined above. |
Additionally, I would annotate both the Generated and Hand-written mappers if one desire to get them discovered (something like @Mapper and @ManualMapper). In my humble opinion it will give the framework good level of consistency. But I love it already, so you must be doing something right! |
I meant that you only have to specify your list of mappers once.. You could use it as a kind of central mapper repository. I'm not sure though how MapStruct handles a reference to the mapper itself. |
Would it be possible to enable dynamic discovery of the mapper classes used in a generated code according to the source and target class through the package annotation configuration like:
@Mapper (usesPackage = {"org.company.componenent.mappers"})
The text was updated successfully, but these errors were encountered: