@Jacksonized: modify generated @(Super)Builders such that they will be used by Jackson's deserialization #2387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the proposal discussed here.
Adding
@Jacksonized
to a context where there is also a@Builder
or@SuperBuilder
annotation does the following:@JsonDeserialize(builder=MyClass.MyClassBuilder[Impl].class))
on the class. (An error is emitted if such an annotation already exists.)@JsonIgnoreProperties
) from the class to the builder class. This is necessary so that Jackson recognizes them when using the builder.@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 using usingbuildMethodName
, this is also made known to Jackson.@SuperBuilder
, make the builder implementation class package-private.There is one minor difference to the proposal (with regard to step 1.): If there is already a
@JsonDeserialize
annotation on the class, it will give an error. The reason is that all other parameters of@JsonDeserialize
are only useful when not using a builder; often they will even contradict the usage of a builder. So I though it is reasonable to error out then and let the user decide what to do.I did not yet write documentation for the website, because I didn't where to place it (there is no "external" section in the site). I propose adding it as "experimental".