@Jacksonized
Bob, meet Jackson. Lets make sure you become fast friends.
@Jacksonized
was introduced as experimental feature in lombok v1.18.14.
Overview
The @Jacksonized
annotation is an add-on annotation for @Builder
and @SuperBuilder
.
It automatically configures the generated builder class to be used by Jackson's deserialization.
It only has an effect if present at a context where there is also a @Builder
or a @SuperBuilder
; a warning is emitted otherwise.
Without @Jacksonized
, you would have to customize your builder class(es).
With @Jacksonized
, you can simply write something like this to let Jackson use the generated builder:
@Jacksonized @Builder @JsonIgnoreProperties(ignoreUnknown = true) public class JacksonExample { private List<Foo> foos; }
This annotation does not change the behavior of the generated builder.
A @Jacksonized
@SuperBuilder
remains fully compatible to regular @SuperBuilder
s.
Small print
In particular, the annotation does the following:
-
Configure Jackson to use the builder for deserialization using
@JsonDeserialize(builder=Foobar.FoobarBuilder[Impl].class))
on the class (where Foobar is the name of the annotated class, andImpl
is added for@SuperBuilder
). (An error is emitted if such an annotation already exists.) -
Copy Jackson-related configuration annotations (like
@JsonIgnoreProperties
) from the class to the builder class. This is necessary so that Jackson recognizes them when using the builder. -
Insert
@JsonPOJOBuilder(withPrefix="")
on the generated builder class to override Jackson's default prefix "with". If you configured a different prefix in lombok usingsetterPrefix
, this value is used. If you changed the name of thebuild()
method usingbuildMethodName
, this is also made known to Jackson. -
For
@SuperBuilder
, make the builder implementation class package-private.