Many lombok users also use Jackson to (de)serialize JSON. One particular issue is that people want their DTOs to be immutable, requiring an @AllArgsConstructor with @ConstructorProperties. As that annotation may not be available in Java 9+, using a builder is a good alternative (also because you do not need a public @AllArgsConstructor with all that parameters).
That is possible, but you have to either use "with" as setter prefix in the builder (ugly), or customize the generated builder with @JsonPOJOBuilder(withPrefix="") (manual work, especially nasty for @SuperBuilder because of the complexity of the generated code). Furthermore, you have to advise Jackson to use the (generated) builder class via @JsonDeserialize(builder=MyDto.MyDtoBuilder.class). In case of @SuperBuilder, this is even more difficult, because you need to put the BuilderImpl class in there, which is private by default and thus not accessible in the @JsonDeserialize annotation.
As discussed
here on GitHub, lombok could add a new annotation that simplifies this use-case. I'll call it
@Jacksonized for now. One way to go could be to cater to the Jackson needs if
@Jacksonized is present (like using "with" as prefix then). I don't like that.
Instead I propose the following approach whenever @Jacksonized is present at a place where there is also a @(Super)Builder annotation:
1. Insert (or modify if already present) @JsonDeserialize(builder=MyDto.MyDtoBuilder[Impl].class) on the class.
2. Copy Jackson-related configuration annotations (like
@JsonIgnoreProperties) to the builder class. According to the
Jackson docs, this is necessary.
3. Insert @JsonPOJOBuilder(withPrefix="") to avoid the ugly "with" prefix in the builder.
4. For @SuperBuilder, make the builder implemention class package-private.
What do you think?