-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Lombok put annotation on builder method parameter instead method itself #1961
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
Comments
It's intended, because annotations like In this case, this does not work with Jackson, but I don't know a good way to solve it. I'm not a lombok maintainer, but to me it seems that adding more config options will push the complexity of this feature too much towards incomprehensibility. So my suggestion is to request a feature with Jackson so that |
@janrieke I agree that it's (mostly) a Jackson issue, but otherwise disagree. Now, we have Copying annotations to the builder opens even more choices. While I can't imagine configuring all possible target places individually, I'm afraid that it's the best solution since otherwise, there'll be always someone missing an option. Let's hope, I'm wrong. |
I disagree that this is "safer choice" regardless of my usecase here.
Note that TestAnn annotation cannot be used on method parameter by target restriction, though, when I do delombok I'm getting this:
This is plain wrong usage. |
That's why you have to explicitly switch on copying for your annotation, because lombok cannot know if the annotation is also for But of course that's not safe, it's just more likely to be valid. If we want to be able to support all cases, lombok would need separate config options |
Well, yes... covering all possibilities might be unfeasible. Reasonable defaults are also good, but I believe that for cases like this there must be some sort of escape hatch. Global configuration is way too general to handle this. Maybe additional annotation(s) that control where other annotations should be copied would be a better approach (at least more granular). |
|
Are you sure? My idea would be to allow to configure exactly where an annotation should go, but only globally. This makes it much more complicated than the current state ("copy to where it makes sense most of the time"), but still very simple when compared to your proposal. It's also much less verbose, as you don't need to repeat the information for every field. Are there case when you want e.g., |
I don't have any usecases where JsonProperty should go not to a method but I assume someone might have. My proposal is not a replacement for global configuration, but merely an escape hatch for situations when someone want to override behavior that in all other cases is fine. Situation with NotNull annotation above is an example where you might want that. Verbosity could be mitigated by making @CopyToBuilderAs annotation attachable at class level and therefore work for all fields in the class. |
Lombok version is 1.18.4
My Test.java file is this:
lombok.config file is like this:
I.e. I want @JsonProperty annotation copied to builder method so jackson can actually use builder properly.
When I do "delombok" like this:
java -jar lombok-1.18.4.jar delombok -p Test.java > d_Test.java
resulting file contains following:
Note that @JsonProperty is attached to parameter of the method, not to a method itself, which confuses jackson and it won't do proper deserialization. If I manually move annotation to method, everything works.
Is this some sort of a bug or this is intended behavior?
The text was updated successfully, but these errors were encountered: