-
-
Notifications
You must be signed in to change notification settings - Fork 916
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
Support @Named variables to address mapper inheritance when super is not located in same jar #1198
Comments
…e when super is not located in same jar
As I wrote in the PR #1199 I find this feature really interesting and useful. The implementation looks pretty simple as well. I would only prefer using some other annotation like @jmuis is using a different annotation acceptable for you? |
Hmm, interesting. We talked about a similar problem in #847 |
@agudian where is this talked about in the linked PR? Sorry, I couldn't find it :(. Are you talking about this:
If that is the case, it is similar, but not that much. I also didn't understand what was the consensus there. Did you agree on something or not? |
Hi @jmuis it's not quite clear to me yet how reflection plays into this. MapStruct works at compile time, so it should have access to the parameter names of the methods for which it generates implementations. Could you provide some more context perhaps? Thanks! |
@jmuis, got it now - when creating an implementation for a method defined in another JAR the parameter name will be lost. But as you said, Java 8 allows to retain parameter names. I'd strongly prefer to take advantage of that standard facility instead of adding our own solution. What is it that speaks against it? |
Hi @gunnarmorling , |
I see an added value.. Certainly in the context of #847 . I'm not sure whether we should use
So I would argue that we need a new annotation. Since they would be in line in a method definition they should be short. What about |
Hey, after some more discussion with the team we've decided to not support this for now. Java 8 provides a way to retain parameters in class files and this should be the preferred approach. I hear what you are saying about the class file size, but I don't think it'll make a significant difference in practice. Should we end up adding a new naming annotation in the context of that issue mentioned by @sjaakd, we still can re-evaluate, but for now I'm going to close this issue. Thanks nevertheless for coming up with the proposal and implementation, your efforts are much appreciated! |
Hi,
We have a case where we need to have a mapper interface with 2 different implementations, which implementation will be chosen runtime is basically dependent upon the way we need to retrieve additional data for the mapper (target property uses a java expression to fetch mapping data).
Because these 2 implementations resist in 2 different jars and the mapper interface in a 3rd jar reflection the actual parameter names get lots through the java compiler and end up as arg0, arg1, arg2, etc. Example mapper method: void mapMyData(Type1 arg0, Type2 arg2, ....) where the original interface specifies mapMyData(Type1 type1, Type2 type2, ... )
You will now have to use arg0, arg1, etc. in your java expression or you will get a compile error.
You can avoid this when using java 8 and adding parameter names compiler options, but we would like to avoid this very much.
Project structure:
+@mapping(target="...", expression="java(...)")
interface mapper(...) extends my-mapper-interface {}
@mapping(target="...", expression="java(...)")
Possible solution (will add a merge request later) is to use @nAmed annotations on the parameter, which would then be used by the annotation processor to not use the java generated parameter name (arg0) but the value of the @nAmed annotation.
The text was updated successfully, but these errors were encountered: