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

@Jacksonized: modify generated @(Super)Builders such that they will be used by Jackson's deserialization #2387

Merged
merged 3 commits into from
Mar 5, 2020

Conversation

janrieke
Copy link
Contributor

@janrieke janrieke commented Mar 3, 2020

This PR implements the proposal discussed here.

Adding @Jacksonized to a context where there is also a @Builder or @SuperBuilder annotation does the following:

  1. Configure Jackson to use the builder for deserialization using @JsonDeserialize(builder=MyClass.MyClassBuilder[Impl].class)) on the class. (An error is emitted if such an annotation already exists.)
  2. 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.
  3. Insert @JsonPOJOBuilder(withPrefix="") on the generated builder class to override Jackson's default prefix "with". If you configured a different prefix in lombok using setterPrefix, this value is used. If you changed the name of the build() method using using buildMethodName, this is also made known to Jackson.
  4. For @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".

@janrieke
Copy link
Contributor Author

janrieke commented Mar 5, 2020

I pushed two new commits to the branch/PR:

  • add flag usage configuration key (I just noticed I forgot this)
  • add documentation and changelog entry

@rzwitserloot rzwitserloot merged commit ed412b7 into projectlombok:master Mar 5, 2020
@rzwitserloot
Copy link
Collaborator

This is amazing work, @janrieke – all I really had to do was think of a funny byline :)

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

Successfully merging this pull request may close these issues.

4 participants