It would be nice to be able to configure the builder method name prefix Jackson uses either globally through a configuration on ObjectMapper or through the @JsonDeserialize annotation itself. I'm currently using Lombok to generate my builders for me and to make it work nicely with Jackson I have to write boilerplate code, which is the whole point of lombok.
The Problem
Currently, in order to use Jackson and lombok in tandem, I have to write a model class like this:
@Builder
@JsonDeserialize(builder = Model.ModelBuilder.class)
public class Model {
/** various properties */
@JsonPOJOBuilder(withPrefix = "")
public static class ModelBuilder {
}
}
The issue becomes even worse if using the @SuperBuilder annotation:
@SuperBuilder
@JsonDeserialize(builder = Model.ModelBuilderImpl.class)
public class Model extends AbstractModel {
/** various properties */
@JsonPOJOBuilder(withPrefix = "")
protected static final class ModelBuilderImpl extends Model.ModelBuilder<Model, Model.ModelBuilderImpl> {
}
}
There's also a blurb about the workaround in Lombok's own documentation.
Related issue: https://github.com/FasterXML/jackson-databind/issues/1997
Global Config
One way to fix it would be to allow this to be configured globally on ObjectMapper like:
objectMapper.configure(DeserializationFeature.POJO_BUILDER_PREFIX, "");
JsonDeserialize Property
Another solution would be to allow it to be set on the @JsonDeserialize annotation itself, like:
@JsonDeserialize(builder = Model.ModelBuilder.class, withBuilderPrefix = "")
Personally, I prefer option 2.
It would be nice to be able to configure the builder method name prefix Jackson uses either globally through a configuration on
ObjectMapperor through the@JsonDeserializeannotation itself. I'm currently using Lombok to generate my builders for me and to make it work nicely with Jackson I have to write boilerplate code, which is the whole point of lombok.The Problem
Currently, in order to use Jackson and lombok in tandem, I have to write a model class like this:
The issue becomes even worse if using the
@SuperBuilderannotation:There's also a blurb about the workaround in Lombok's own documentation.
Related issue: https://github.com/FasterXML/jackson-databind/issues/1997
Global Config
One way to fix it would be to allow this to be configured globally on
ObjectMapperlike:JsonDeserialize Property
Another solution would be to allow it to be set on the
@JsonDeserializeannotation itself, like:Personally, I prefer option 2.