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

[BUG] Lombok with Jackson - @JsonProperty added to the generated setter causes error #2458

Open
JulienHoueix opened this issue May 8, 2020 · 3 comments

Comments

@JulienHoueix
Copy link

Hello,

I have a problem with the last version of Lombok (1.18.12).

The @JsonProperty of the field is copied to the generated setter by Lombok, and that causes an error when an annotation @JacksonXmlProperty also exists on that field.

Here is an example:

import org.junit.Test;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

import lombok.Getter;
import lombok.Setter;

public class LombokTest {

    @Test
    public void test() throws JsonProcessingException {
        MyClass myClass = new MyClass();
        XmlMapper xmlMapper = new XmlMapper();
        String xml = xmlMapper.writeValueAsString(myClass);
    }

}

@Getter
@Setter
class MyClass {

    @JacksonXmlProperty(localName = "MY_FIELD")
    @JsonProperty("my_field")
    private String myField;

}

It causes the following error:
java.lang.IllegalStateException: Conflicting/ambiguous property name definitions (implicit name 'myField'): found multiple explicit names: [{}MY_FIELD, my_field], but also implicit accessor: [method MyClass#getMyField(0 params)][visible=true,ignore=false,explicitName=false]

In 1.18.6 we did not have this error because the annotation @JsonProperty was not added tothe setter in the generated code.

I guess it is related to #1981

@JulienHoueix JulienHoueix changed the title [BUG] [BUG] Lombok with Jackson - @JsonProperty added to the generate setter causes error May 8, 2020
@JulienHoueix JulienHoueix changed the title [BUG] Lombok with Jackson - @JsonProperty added to the generate setter causes error [BUG] Lombok with Jackson - @JsonProperty added to the generated setter causes error May 8, 2020
@janrieke
Copy link
Contributor

Is probably already fixed by PR #2429 (that will also copy @JacksonXmlProperty). However, it's not in the latest edge release, yet.

@janrieke
Copy link
Contributor

janrieke commented Jun 8, 2020

It's now in the latest edge snapshot. Could you check if this fixes your issue?

@JulienHoueix
Copy link
Author

I have tested with lombok-edge-20200528.222155-1 and it fixes the issue, the test passes.

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