From a0a2ef4fbc3f2b4913a7c3b75287872d9f67a079 Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Sun, 21 Jan 2024 23:07:48 +0100 Subject: [PATCH] [WIP] --- .../lombok/extern/jackson/Jacksonized.java | 24 +++++++++++++------ .../javac/handlers/HandleJacksonized.java | 6 +++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/core/lombok/extern/jackson/Jacksonized.java b/src/core/lombok/extern/jackson/Jacksonized.java index 801ddbcbc3..bba654c302 100644 --- a/src/core/lombok/extern/jackson/Jacksonized.java +++ b/src/core/lombok/extern/jackson/Jacksonized.java @@ -27,13 +27,23 @@ 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}. + *

+ * 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. + *

+ * 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. @@ -41,8 +51,8 @@ * In particular, the annotation does the following: *

- * This annotation does not change the behavior of the generated builder. - * A {@code @Jacksonized} {@code @SuperBuilder} remains fully compatible to - * regular {@code @SuperBuilder}s. + * This annotation does not 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) diff --git a/src/core/lombok/javac/handlers/HandleJacksonized.java b/src/core/lombok/javac/handlers/HandleJacksonized.java index 3ee0eec4e0..7b1cb63f81 100644 --- a/src/core/lombok/javac/handlers/HandleJacksonized.java +++ b/src/core/lombok/javac/handlers/HandleJacksonized.java @@ -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; @@ -73,8 +74,9 @@ public class HandleJacksonized extends JavacAnnotationHandler { 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; }