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

Is there an option to exclude Jackson annotations? #2277

Open
prondzyn opened this issue Oct 31, 2019 · 4 comments
Open

Is there an option to exclude Jackson annotations? #2277

prondzyn opened this issue Oct 31, 2019 · 4 comments
Labels
parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these.

Comments

@prondzyn
Copy link

Hi.

I have a question about my situation. I've upgraded the Lombok version in my project from 1.18.8 to 1.18.10. After this change, it started to use @JsonSetter values to generate fields in a JSON output. Please take a look at below example:

I have a Dog object:

@Getter
class Dog {
  @JsonSetter("favourite_meal")
  private String favouriteMeal;
}

In version 1.18.8 I was getting such JSON output:

{
  "favouriteMeal" : "rice"
}

while with version 1.18.10 I have:

{
  "favourite_meal" : "rice"
}

Is there an option to have the old output with the newest version of Lombok? I found in https://projectlombok.org/changelog something like lombok.copyableAnnotations but as far as I see I can only add other annotations with it and not exclude some. Please advise.

@Maaartinus
Copy link
Contributor

I'd try

lombok.copyableAnnotations -= com.fasterxml.jackson.annotation.JsonSetter

No idea, if it works; you can use delombok to see the generated code.

Why do you need the @JsonSetter at all? Does it allow using both favouriteMeal and favourite_meal in the input?

@rzwitserloot rzwitserloot added the parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these. label Jan 15, 2020
@rzwitserloot
Copy link
Collaborator

There is no way to revert to old behaviour.

I need context here; I am not a user of jackson at all. Issue 2168 conflicts with what you want and I have no idea how this works.

@prondzyn
Copy link
Author

@rzwitserloot what kind of context do you need? I described the entire example above. Is there any option to force Lombok in newest version to not take @JsonSetter-s into account?

@janrieke
Copy link
Contributor

janrieke commented Apr 17, 2020

That's a Jackson bug, not a lombok issue. Jackson docs say:

As with renaming, note that annotations are "shared" between matching fields, getters and setters: if only one has @JsonIgnore, it affects others.

That is obviously not true for @JsonSetter: If it would be shared between field, getter, and setter, there should be no difference whether you put it just on the field or both on the field and the setter.
However, once you put a @JsonSetter on the setter, it affects the serialization. You may even put it on the getter without affecting the serialization, which is even more confusing. I reproduced all that cases completely without lombok.

Besides that observation, in FasterXML/jackson-databind#1519 a Jackson developer says that it's intended that this annotation also affects serialization, so it's not the correct annotation for your use case. IMHO the JavaDoc for this annotation is misleading, I would have made the same mistake. For your usecase, @JsonAlias("favourite_meal") makes it work.

Nevertheless, you should file a bug report for FasterXML/jackson-databind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these.
Projects
None yet
Development

No branches or pull requests

4 participants