mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 04:16:19 +00:00
[WIP]
This commit is contained in:
1 parent
54d57f896d
commit
a0a2ef4fbc
2 files changed
+21
-9
No files matched your search
+17
-7
@@ -27,13 +27,23 @@ import static java.lang.annotation.RetentionPolicy.*;
|
||||
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.
|
||||
@@ -41,8 +51,8 @@ import lombok.experimental.SuperBuilder;
|
||||
* 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>
|
||||
@@ -54,9 +64,9 @@ import lombok.experimental.SuperBuilder;
|
||||
* <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)
|
||||
|
||||
@@ -42,6 +42,7 @@ import lombok.core.AST.Kind;
|
||||
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<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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user