Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
janrieke committed Jan 21, 2024
1 parent 54d57f8 commit a0a2ef4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
24 changes: 17 additions & 7 deletions src/core/lombok/extern/jackson/Jacksonized.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,32 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Builder;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;

/**
* The {@code @Jacksonized} annotation is an add-on annotation for
* {@code @}{@link Builder} and {@code @}{@link SuperBuilder}. It automatically
* configures the generated builder class to be used by Jackson's
* {@code @}{@link Builder}, {@code @}{@link SuperBuilder}, and
* {@code @}{@link Accessors}.
* <p>
* For {@code @}{@link Accessors}{@code (fluent = true)}, it automatically
* configures Jackson to use the generated setters and getters for
* (de-)serialization by inserting {@code @}{@link JsonProperty} annotations.
* <p>
* For {@code @}{@link Builder} and {@code @}{@link 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 {@code @Builder} or a {@code @SuperBuilder}; a warning is emitted
* otherwise.
* <p>
* In particular, the annotation does the following:
* <ul>
* <li>Configure Jackson to use the builder for deserialization using
* {@code @JsonDeserialize(builder=Foobar.FoobarBuilder[Impl].class)}
* on the class (where <em>Foobar</em> is the name of the annotated class).</li>
* {@code @JsonDeserialize(builder=Foobar.FoobarBuilder[Impl].class)} on the
* class (where <em>Foobar</em> is the name of the annotated class).</li>
* <li>Copy Jackson-related configuration annotations (like
* {@code @JsonIgnoreProperties}) from the class to the builder class. This is
* necessary so that Jackson recognizes them when using the builder.</li>
Expand All @@ -54,9 +64,9 @@
* <li>For {@code @SuperBuilder}, make the builder implementation class
* package-private.</li>
* </ul>
* This annotation does <em>not</em> change the behavior of the generated builder.
* A {@code @Jacksonized} {@code @SuperBuilder} remains fully compatible to
* regular {@code @SuperBuilder}s.
* This annotation does <em>not</em> change the behavior of the generated
* builder. A {@code @Jacksonized} {@code @SuperBuilder} remains fully
* compatible to regular {@code @SuperBuilder}s.
*/
@Target({TYPE, METHOD, CONSTRUCTOR})
@Retention(SOURCE)
Expand Down
6 changes: 4 additions & 2 deletions src/core/lombok/javac/handlers/HandleJacksonized.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import lombok.core.AnnotationValues;
import lombok.core.HandlerPriority;
import lombok.core.handlers.HandlerUtil;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;
import lombok.javac.JavacAnnotationHandler;
Expand Down Expand Up @@ -73,8 +74,9 @@ public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> {

JavacNode builderAnnotationNode = findAnnotation(Builder.class, annotatedNode);
JavacNode superBuilderAnnotationNode = findAnnotation(SuperBuilder.class, annotatedNode);
if (builderAnnotationNode == null && superBuilderAnnotationNode == null) {
annotationNode.addWarning("@Jacksonized requires @Builder or @SuperBuilder for it to mean anything.");
JavacNode accessorsAnnotationNode = findAnnotation(Accessors.class, annotatedNode);
if (builderAnnotationNode == null && superBuilderAnnotationNode == null && accessorsAnnotationNode == null) {
annotationNode.addWarning("@Jacksonized requires @Builder, @SuperBuilder, or @Accessors for it to mean anything.");
return;
}

Expand Down

0 comments on commit a0a2ef4

Please sign in to comment.