From 8be4b0ffe6b5e5f89e8bb3d94e87d0aa98dc5aeb Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Sun, 16 Feb 2020 15:17:20 +0100 Subject: @Jacksonized: modify builders that they can be used by Jackson --- src/core/lombok/extern/jackson/Jacksonized.java | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/core/lombok/extern/jackson/Jacksonized.java (limited to 'src/core/lombok/extern/jackson/Jacksonized.java') diff --git a/src/core/lombok/extern/jackson/Jacksonized.java b/src/core/lombok/extern/jackson/Jacksonized.java new file mode 100644 index 00000000..0f98cb33 --- /dev/null +++ b/src/core/lombok/extern/jackson/Jacksonized.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2020 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.extern.jackson; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import lombok.Builder; +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 + * 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. + *

+ * 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. + */ +@Target({TYPE, METHOD, CONSTRUCTOR}) +@Retention(SOURCE) +public @interface Jacksonized { +} -- cgit From a749bc230f4e42904dc6803841cfb928c394d3b5 Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Thu, 5 Mar 2020 16:25:09 +0100 Subject: @Jacksonized: add flag usage configuration key --- src/core/lombok/ConfigurationKeys.java | 9 +++++++++ src/core/lombok/eclipse/handlers/HandleJacksonized.java | 3 +++ src/core/lombok/extern/jackson/Jacksonized.java | 10 +++++----- src/core/lombok/javac/handlers/HandleJacksonized.java | 3 +++ 4 files changed, 20 insertions(+), 5 deletions(-) (limited to 'src/core/lombok/extern/jackson/Jacksonized.java') diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index 8a028858..46cf7412 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -651,6 +651,15 @@ public class ConfigurationKeys { * If set, any usage of {@code @WithBy} results in a warning / error. */ public static final ConfigurationKey WITHBY_FLAG_USAGE = new ConfigurationKey("lombok.withBy.flagUsage", "Emit a warning or error if @WithBy is used.") {}; + + // ----- Jacksonized ----- + + /** + * lombok configuration: {@code lombok.jacksonized.flagUsage} = {@code WARNING} | {@code ERROR}. + * + * If set, any usage of {@code @Jacksonized} results in a warning / error. + */ + public static final ConfigurationKey JACKSONIZED_FLAG_USAGE = new ConfigurationKey("lombok.jacksonized.flagUsage", "Emit a warning or error if @Jacksonized is used.") {}; // ----- Configuration System ----- diff --git a/src/core/lombok/eclipse/handlers/HandleJacksonized.java b/src/core/lombok/eclipse/handlers/HandleJacksonized.java index 8d1ffb04..90ee7582 100644 --- a/src/core/lombok/eclipse/handlers/HandleJacksonized.java +++ b/src/core/lombok/eclipse/handlers/HandleJacksonized.java @@ -21,6 +21,7 @@ */ package lombok.eclipse.handlers; +import static lombok.core.handlers.HandlerUtil.handleExperimentalFlagUsage; import static lombok.eclipse.handlers.EclipseHandlerUtil.*; import java.util.ArrayList; @@ -62,6 +63,8 @@ public class HandleJacksonized extends EclipseAnnotationHandler { private static final char[][] JSON_DESERIALIZE_ANNOTATION = Eclipse.fromQualifiedName("com.fasterxml.jackson.databind.annotation.JsonDeserialize"); @Override public void handle(AnnotationValues annotation, Annotation ast, EclipseNode annotationNode) { + handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.JACKSONIZED_FLAG_USAGE, "@Jacksonized"); + EclipseNode annotatedNode = annotationNode.up(); EclipseNode tdNode; diff --git a/src/core/lombok/extern/jackson/Jacksonized.java b/src/core/lombok/extern/jackson/Jacksonized.java index 0f98cb33..cf6678da 100644 --- a/src/core/lombok/extern/jackson/Jacksonized.java +++ b/src/core/lombok/extern/jackson/Jacksonized.java @@ -41,20 +41,20 @@ import lombok.experimental.SuperBuilder; * In particular, the annotation does the following: *
    *
  • Configure Jackson to use the builder for deserialization using - * {@code @JsonDeserialize(builder=MyClass.MyClassBuilder[Impl].class))} on the - * class. (An error is emitted if such an annotation already exists.) + * {@code @JsonDeserialize(builder=Foobar.FoobarBuilder[Impl].class)} + * on the class (where Foobar is the name of the annotated class).
  • *
  • 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. + * necessary so that Jackson recognizes them when using the builder.
  • *
  • Insert {@code @JsonPOJOBuilder(withPrefix="")} on the generated builder * class to override Jackson's default prefix "with". If you configured a * different prefix in lombok using {@code setterPrefix}, this value is used. If * you changed the name of the {@code build()} method using using - * {@code buildMethodName}, this is also made known to Jackson. + * {@code buildMethodName}, this is also made known to Jackson.
  • *
  • For {@code @SuperBuilder}, make the builder implementation class * package-private.
  • *
- * This annotation does not change the behavior of the generated builder. + * This annotation does not change the behavior of the generated builder. * A {@code @Jacksonized} {@code @SuperBuilder} remains fully compatible to * regular {@code @SuperBuilder}s. */ diff --git a/src/core/lombok/javac/handlers/HandleJacksonized.java b/src/core/lombok/javac/handlers/HandleJacksonized.java index 889dd27d..aff0bf63 100644 --- a/src/core/lombok/javac/handlers/HandleJacksonized.java +++ b/src/core/lombok/javac/handlers/HandleJacksonized.java @@ -21,6 +21,7 @@ */ package lombok.javac.handlers; +import static lombok.core.handlers.HandlerUtil.handleExperimentalFlagUsage; import static lombok.javac.handlers.JavacHandlerUtil.*; import org.mangosdk.spi.ProviderFor; @@ -59,6 +60,8 @@ import lombok.javac.JavacTreeMaker; public class HandleJacksonized extends JavacAnnotationHandler { @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { + handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.JACKSONIZED_FLAG_USAGE, "@Jacksonized"); + JavacNode annotatedNode = annotationNode.up(); deleteAnnotationIfNeccessary(annotationNode, Jacksonized.class); -- cgit