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] Problem using @Jacksonized with @JsonPOJOBuilder #3303

Open
JonCook opened this issue Nov 23, 2022 · 2 comments
Open

[BUG] Problem using @Jacksonized with @JsonPOJOBuilder #3303

JonCook opened this issue Nov 23, 2022 · 2 comments

Comments

@JonCook
Copy link

JonCook commented Nov 23, 2022

Hello,

I have the following simple POJO:

@Data
@Builder(builderClassName = "EmployeeBuilder")
@Jacksonized
public class Employee {

    private int identity;
    private String firstName;
    
    @JsonPOJOBuilder(buildMethodName = "createEmployee", withPrefix = "construct")
    public static class EmployeeBuilder {

        private int idValue;
        private String nameValue;

        public EmployeeBuilder constructId(int id) {
            idValue = id;
            return this;
        }
            
        public EmployeeBuilder constructName(String name) {
            nameValue = name;
            return this;
        }

        public Employee createEmployee() {
            return new Employee(idValue, nameValue);
        }
    }
}

Everything compiles and works in Eclipse OK, however when I try to compile via Maven and JDK jdk8u345-b01 I get the following error:

Employee.java:[15,8] com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder is not a repeatable annotation type

I've no idea what this even means to be honest but I'm using the latest version of Lombok 1.18.24 and Jackson 2.14.0

If I use the following, it works as well:

@Data 
@Builder(builderClassName = "EmployeeBuilder") 
@JsonDeserialize(builder = Employee.EmployeeBuilder.class) 
@AllArgsConstructor

So removing @Jacksonized seems to solve the problem?

Thanks,

@janrieke
Copy link
Contributor

janrieke commented Nov 24, 2022

See StackOverflow for a more detailed answer.

In short: You are manually adding @JsonPOJOBuilder, but that's also generated by Lombok's @Jacksonized.

We could improve that by letting @Jacksonized check for an existing @JsonPOJOBuilder (as we do already for @JsonDeserialize) and print a meaningful error then.

However, low-prio IMO.

@JonCook
Copy link
Author

JonCook commented Nov 24, 2022

Thanks for the reply @janrieke - I replied on stackoverflow

Yes agree low-prio or add something to the documentation.

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