From e3c9e3d9ffed6957c45f4c0a045fb0b91d13f8a0 Mon Sep 17 00:00:00 2001 From: Liam Pace <146035497+liampace@users.noreply.github.com> Date: Thu, 18 Sep 2025 01:18:19 -0400 Subject: [PATCH 1/7] Add transforms to include checks for transient field --- .../JacksonizedAccessorsTransient.java | 20 +++++++++++++++++++ .../JacksonizedAccessorsTransient.java | 16 +++++++++++++++ .../before/JacksonizedAccessorsTransient.java | 7 +++++++ 3 files changed, 43 insertions(+) create mode 100644 test/transform/resource/after-delombok/JacksonizedAccessorsTransient.java create mode 100644 test/transform/resource/after-ecj/JacksonizedAccessorsTransient.java create mode 100644 test/transform/resource/before/JacksonizedAccessorsTransient.java diff --git a/test/transform/resource/after-delombok/JacksonizedAccessorsTransient.java b/test/transform/resource/after-delombok/JacksonizedAccessorsTransient.java new file mode 100644 index 00000000..4db7280c --- /dev/null +++ b/test/transform/resource/after-delombok/JacksonizedAccessorsTransient.java @@ -0,0 +1,20 @@ +public class JacksonizedAccessorsTransient { + @com.fasterxml.jackson.annotation.JsonIgnore + private transient int intValue; + @com.fasterxml.jackson.annotation.JsonIgnore + @java.lang.SuppressWarnings("all") + @lombok.Generated + public int intValue() { + return this.intValue; + } + /** + * @return {@code this}. + */ + @com.fasterxml.jackson.annotation.JsonIgnore + @java.lang.SuppressWarnings("all") + @lombok.Generated + public JacksonizedAccessorsTransient intValue(final int intValue) { + this.intValue = intValue; + return this; + } +} \ No newline at end of file diff --git a/test/transform/resource/after-ecj/JacksonizedAccessorsTransient.java b/test/transform/resource/after-ecj/JacksonizedAccessorsTransient.java new file mode 100644 index 00000000..ad318f73 --- /dev/null +++ b/test/transform/resource/after-ecj/JacksonizedAccessorsTransient.java @@ -0,0 +1,16 @@ +public @lombok.extern.jackson.Jacksonized @lombok.experimental.Accessors(fluent = true) @lombok.Getter @lombok.Setter class JacksonizedAccessorsTransient { + private transient @com.fasterxml.jackson.annotation.JsonIgnore int intValue; + public JacksonizedAccessorsTransient() { + super(); + } + public @com.fasterxml.jackson.annotation.JsonIgnore @java.lang.SuppressWarnings("all") @lombok.Generated int intValue() { + return this.intValue; + } + /** + * @return {@code this}. + */ + public @com.fasterxml.jackson.annotation.JsonIgnore @java.lang.SuppressWarnings("all") @lombok.Generated JacksonizedAccessorsTransient intValue(final int intValue) { + this.intValue = intValue; + return this; + } +} \ No newline at end of file diff --git a/test/transform/resource/before/JacksonizedAccessorsTransient.java b/test/transform/resource/before/JacksonizedAccessorsTransient.java new file mode 100644 index 00000000..6b04e62c --- /dev/null +++ b/test/transform/resource/before/JacksonizedAccessorsTransient.java @@ -0,0 +1,7 @@ +@lombok.extern.jackson.Jacksonized +@lombok.experimental.Accessors(fluent = true) +@lombok.Getter +@lombok.Setter +public class JacksonizedAccessorsTransient { + private transient int intValue; +} \ No newline at end of file From 3ad435f08241bfd25d01c0519ec3fc1f685ef7d9 Mon Sep 17 00:00:00 2001 From: Liam Pace <146035497+liampace@users.noreply.github.com> Date: Thu, 18 Sep 2025 01:33:31 -0400 Subject: [PATCH 2/7] Refactor eclipse handler --- .../eclipse/handlers/HandleJacksonized.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/core/lombok/eclipse/handlers/HandleJacksonized.java b/src/core/lombok/eclipse/handlers/HandleJacksonized.java index 0a3f5dba..da45c981 100644 --- a/src/core/lombok/eclipse/handlers/HandleJacksonized.java +++ b/src/core/lombok/eclipse/handlers/HandleJacksonized.java @@ -62,9 +62,21 @@ import lombok.spi.Provides; @HandlerPriority(-512) // Above Handle(Super)Builder's level (builders must be already generated). public class HandleJacksonized extends EclipseAnnotationHandler { - private static final char[][] JSON_POJO_BUILDER_ANNOTATION = Eclipse.fromQualifiedName("com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder"); - private static final char[][] JSON_DESERIALIZE_ANNOTATION = Eclipse.fromQualifiedName("com.fasterxml.jackson.databind.annotation.JsonDeserialize"); - private static final char[][] JSON_PROPERTY_ANNOTATION = Eclipse.fromQualifiedName("com.fasterxml.jackson.annotation.JsonProperty"); + private static enum JacksonAnnotations { + JSON_POJO_BUILDER("com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder"), + JSON_DESERIALIZE("com.fasterxml.jackson.databind.annotation.JsonDeserialize"), + JSON_PROPERTY("com.fasterxml.jackson.annotation.JsonProperty"); + + private final String qualifiedName; + private final char[][] annotation; + private JacksonAnnotations(final String qualifiedName) { + this.qualifiedName = qualifiedName; + this.annotation = Eclipse.fromQualifiedName(qualifiedName); + } + private boolean isAnnotating(EclipseNode node) { + return hasAnnotation(this.qualifiedName, node); + } + } @Override public void handle(AnnotationValues annotation, Annotation ast, EclipseNode annotationNode) { handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.JACKSONIZED_FLAG_USAGE, "@Jacksonized"); @@ -132,7 +144,7 @@ public class HandleJacksonized extends EclipseAnnotationHandler { } // Insert @JsonDeserialize on annotated class. - if (hasAnnotation("com.fasterxml.jackson.databind.annotation.JsonDeserialize", tdNode)) { + if (JacksonAnnotations.JSON_DESERIALIZE.isAnnotating(tdNode)) { annotationNode.addError("@JsonDeserialize already exists on class. Either delete @JsonDeserialize, or remove @Jacksonized and manually configure Jackson."); return; } @@ -140,7 +152,7 @@ public class HandleJacksonized extends EclipseAnnotationHandler { TypeReference builderClassExpression = namePlusTypeParamsToTypeReference(builderClassNode, null, p); ClassLiteralAccess builderClassLiteralAccess = new ClassLiteralAccess(td.sourceEnd, builderClassExpression); MemberValuePair builderMvp = new MemberValuePair("builder".toCharArray(), td.sourceStart, td.sourceEnd, builderClassLiteralAccess); - td.annotations = addAnnotation(td, td.annotations, JSON_DESERIALIZE_ANNOTATION, builderMvp); + td.annotations = addAnnotation(td, td.annotations, JacksonAnnotations.JSON_DESERIALIZE.annotation, builderMvp); // Copy annotations from the class to the builder class. Annotation[] copyableAnnotations = findJacksonAnnotationsOnClass(td, tdNode); @@ -151,7 +163,7 @@ public class HandleJacksonized extends EclipseAnnotationHandler { MemberValuePair withPrefixMvp = new MemberValuePair("withPrefix".toCharArray(), builderClass.sourceStart, builderClass.sourceEnd, withPrefixLiteral); StringLiteral buildMethodNameLiteral = new StringLiteral(buildMethodName.toCharArray(), builderClass.sourceStart, builderClass.sourceEnd, 0); MemberValuePair buildMethodNameMvp = new MemberValuePair("buildMethodName".toCharArray(), builderClass.sourceStart, builderClass.sourceEnd, buildMethodNameLiteral); - builderClass.annotations = addAnnotation(builderClass, builderClass.annotations, JSON_POJO_BUILDER_ANNOTATION, withPrefixMvp, buildMethodNameMvp); + builderClass.annotations = addAnnotation(builderClass, builderClass.annotations, JacksonAnnotations.JSON_POJO_BUILDER.annotation, withPrefixMvp, buildMethodNameMvp); // @SuperBuilder? Make it package-private! if (superBuilderAnnotationNode != null) @@ -181,12 +193,12 @@ public class HandleJacksonized extends EclipseAnnotationHandler { } private void createJsonPropertyForField(EclipseNode fieldNode, EclipseNode annotationNode) { - if (hasAnnotation("com.fasterxml.jackson.annotation.JsonProperty", fieldNode)) return; + if (JacksonAnnotations.JSON_PROPERTY.isAnnotating(fieldNode)) return; ASTNode astNode = fieldNode.get(); if (astNode instanceof FieldDeclaration) { FieldDeclaration fd = (FieldDeclaration)astNode; StringLiteral fieldName = new StringLiteral(fd.name, 0, 0, 0); - ((FieldDeclaration) astNode).annotations = addAnnotation(fieldNode.get(), fd.annotations, JSON_PROPERTY_ANNOTATION, fieldName); + ((FieldDeclaration) astNode).annotations = addAnnotation(fieldNode.get(), fd.annotations, JacksonAnnotations.JSON_PROPERTY.annotation, fieldName); } } From fa3030211e07aea307225667d0b7e3ac0712176e Mon Sep 17 00:00:00 2001 From: Liam Pace <146035497+liampace@users.noreply.github.com> Date: Thu, 18 Sep 2025 01:50:30 -0400 Subject: [PATCH 3/7] Refactor javac handlers --- .../javac/handlers/HandleJacksonized.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/core/lombok/javac/handlers/HandleJacksonized.java b/src/core/lombok/javac/handlers/HandleJacksonized.java index 689e3d6d..61400559 100644 --- a/src/core/lombok/javac/handlers/HandleJacksonized.java +++ b/src/core/lombok/javac/handlers/HandleJacksonized.java @@ -60,6 +60,24 @@ import lombok.spi.Provides; @HandlerPriority(-512) // Above Handle(Super)Builder's level (builders must be already generated), but before all handlers generating getters/setters. public class HandleJacksonized extends JavacAnnotationHandler { + private static enum JacksonAnnotations { + JSON_POJO_BUILDER("com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder"), + JSON_DESERIALIZE("com.fasterxml.jackson.databind.annotation.JsonDeserialize"), + JSON_PROPERTY("com.fasterxml.jackson.annotation.JsonProperty"), + JSON_IGNORE("com.fasterxml.jackson.annotation.JsonIgnore"); + + private final String qualifiedName; + private final String[] chainedDots; + private JacksonAnnotations(final String qualifiedName) { + this.qualifiedName = qualifiedName; + this.chainedDots = qualifiedName.split("\\."); + } + + private boolean isAnnotating(JavacNode node) { + return hasAnnotation(this.qualifiedName, node); + } + } + @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.JACKSONIZED_FLAG_USAGE, "@Jacksonized"); @@ -109,12 +127,12 @@ public class HandleJacksonized extends JavacAnnotationHandler { } private void createJsonPropertyForField(JavacNode fieldNode, JavacNode annotationNode) { - if (hasAnnotation("com.fasterxml.jackson.annotation.JsonProperty", fieldNode)) { + if (JacksonAnnotations.JSON_PROPERTY.isAnnotating(fieldNode)) { return; } JavacTreeMaker maker = fieldNode.getTreeMaker(); - JCExpression jsonPropertyType = chainDots(fieldNode, "com", "fasterxml", "jackson", "annotation", "JsonProperty"); + JCExpression jsonPropertyType = chainDots(fieldNode, JacksonAnnotations.JSON_PROPERTY.chainedDots); JCAnnotation annotationJsonProperty = maker.Annotation(jsonPropertyType, List.of(maker.Literal(fieldNode.getName()))); recursiveSetGeneratedBy(annotationJsonProperty, annotationNode); JCVariableDecl fieldDecl = ((JCVariableDecl)fieldNode.get()); @@ -164,11 +182,11 @@ public class HandleJacksonized extends JavacAnnotationHandler { } // Insert @JsonDeserialize on annotated class. - if (hasAnnotation("com.fasterxml.jackson.databind.annotation.JsonDeserialize", tdNode)) { + if (JacksonAnnotations.JSON_DESERIALIZE.isAnnotating(tdNode)) { annotationNode.addError("@JsonDeserialize already exists on class. Either delete @JsonDeserialize, or remove @Jacksonized and manually configure Jackson."); return; } - JCExpression jsonDeserializeType = chainDots(annotatedNode, "com", "fasterxml", "jackson", "databind", "annotation", "JsonDeserialize"); + JCExpression jsonDeserializeType = chainDots(annotatedNode, JacksonAnnotations.JSON_DESERIALIZE.chainedDots); JCExpression builderClassExpression = namePlusTypeParamsToTypeReference(maker, tdNode, annotationNode.toName(builderClassName), false, List.nil()); JCFieldAccess builderClassReference = maker.Select(builderClassExpression, annotatedNode.toName("class")); JCExpression assign = maker.Assign(maker.Ident(annotationNode.toName("builder")), builderClassReference); @@ -185,7 +203,7 @@ public class HandleJacksonized extends JavacAnnotationHandler { builderClass.mods.annotations = builderClass.mods.annotations.appendList(copiedAnnotations); // Insert @JsonPOJOBuilder on the builder class. - JCExpression jsonPOJOBuilderType = chainDots(annotatedNode, "com", "fasterxml", "jackson", "databind", "annotation", "JsonPOJOBuilder"); + JCExpression jsonPOJOBuilderType = chainDots(annotatedNode, JacksonAnnotations.JSON_POJO_BUILDER.chainedDots); JCExpression withPrefixExpr = maker.Assign(maker.Ident(annotationNode.toName("withPrefix")), maker.Literal(setPrefix)); JCExpression buildMethodNameExpr = maker.Assign(maker.Ident(annotationNode.toName("buildMethodName")), maker.Literal(buildMethodName)); JCAnnotation annotationJsonPOJOBuilder = maker.Annotation(jsonPOJOBuilderType, List.of(withPrefixExpr, buildMethodNameExpr)); From 3cdc80050e6f70e341400790225420028353621c Mon Sep 17 00:00:00 2001 From: Liam Pace <146035497+liampace@users.noreply.github.com> Date: Thu, 18 Sep 2025 02:07:32 -0400 Subject: [PATCH 4/7] Implement eclipse handler --- .../eclipse/handlers/HandleJacksonized.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/lombok/eclipse/handlers/HandleJacksonized.java b/src/core/lombok/eclipse/handlers/HandleJacksonized.java index da45c981..b6f5c68a 100644 --- a/src/core/lombok/eclipse/handlers/HandleJacksonized.java +++ b/src/core/lombok/eclipse/handlers/HandleJacksonized.java @@ -65,7 +65,9 @@ public class HandleJacksonized extends EclipseAnnotationHandler { private static enum JacksonAnnotations { JSON_POJO_BUILDER("com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder"), JSON_DESERIALIZE("com.fasterxml.jackson.databind.annotation.JsonDeserialize"), - JSON_PROPERTY("com.fasterxml.jackson.annotation.JsonProperty"); + JSON_PROPERTY("com.fasterxml.jackson.annotation.JsonProperty"), + JSON_IGNORE("com.fasterxml.jackson.annotation.JsonIgnore"); + private final String qualifiedName; private final char[][] annotation; @@ -186,7 +188,8 @@ public class HandleJacksonized extends EclipseAnnotationHandler { // Add @JsonProperty to all fields. It will be automatically copied to the getter/setters later. for (EclipseNode eclipseNode : tdNode.down()) { if (eclipseNode.getKind() == Kind.FIELD) { - createJsonPropertyForField(eclipseNode, annotationNode); + if (eclipseNode.isTransient()) createJsonIgnoreForField(eclipseNode, annotationNode); + else createJsonPropertyForField(eclipseNode, annotationNode); } } tdNode.rebuild(); @@ -202,6 +205,15 @@ public class HandleJacksonized extends EclipseAnnotationHandler { } } + private void createJsonIgnoreForField(EclipseNode fieldNode, EclipseNode annotationNode) { + if (JacksonAnnotations.JSON_IGNORE.isAnnotating(fieldNode)) return; + ASTNode astNode = fieldNode.get(); + if (astNode instanceof FieldDeclaration) { + FieldDeclaration fd = (FieldDeclaration)astNode; + ((FieldDeclaration) astNode).annotations = addAnnotation(fieldNode.get(), fd.annotations, JacksonAnnotations.JSON_IGNORE.annotation); + } + } + private String getBuilderClassName(Annotation ast, EclipseNode annotationNode, EclipseNode annotatedNode, TypeDeclaration td, AnnotationValues builderAnnotation) { String builderClassName = builderAnnotation != null ? builderAnnotation.getInstance().builderClassName() : null; From ce9a103dd2d695f2f5af9efddb0d33932c84af25 Mon Sep 17 00:00:00 2001 From: Liam Pace <146035497+liampace@users.noreply.github.com> Date: Thu, 18 Sep 2025 02:11:57 -0400 Subject: [PATCH 5/7] Implement javac handler --- .../javac/handlers/HandleJacksonized.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/core/lombok/javac/handlers/HandleJacksonized.java b/src/core/lombok/javac/handlers/HandleJacksonized.java index 61400559..6a43abe4 100644 --- a/src/core/lombok/javac/handlers/HandleJacksonized.java +++ b/src/core/lombok/javac/handlers/HandleJacksonized.java @@ -118,10 +118,12 @@ public class HandleJacksonized extends JavacAnnotationHandler { return; } - // Add @JsonProperty to all fields. It will be automatically copied to the getter/setters later. + // Add @JsonProperty to all non-transient fields. It will be automatically copied to the getter/setters later. + // Add @JsonIgnore to all transient fields. It will be automatically copied to the getter/setters later. for (JavacNode javacNode : tdNode.down()) { if (javacNode.getKind() == Kind.FIELD) { - createJsonPropertyForField(javacNode, annotationNode); + if (javacNode.isTransient()) createJsonIgnoreForField(javacNode, annotationNode); + else createJsonPropertyForField(javacNode, annotationNode); } } } @@ -139,6 +141,19 @@ public class HandleJacksonized extends JavacAnnotationHandler { fieldDecl.mods.annotations = fieldDecl.mods.annotations.append(annotationJsonProperty); } + private void createJsonIgnoreForField(JavacNode fieldNode, JavacNode annotationNode) { + if (JacksonAnnotations.JSON_IGNORE.isAnnotating(fieldNode)) { + return; + } + JavacTreeMaker maker = fieldNode.getTreeMaker(); + + JCExpression jsonPropertyType = chainDots(fieldNode, JacksonAnnotations.JSON_IGNORE.chainedDots); + JCAnnotation annotationJsonProperty = maker.Annotation(jsonPropertyType, List.nil()); + recursiveSetGeneratedBy(annotationJsonProperty, annotationNode); + JCVariableDecl fieldDecl = ((JCVariableDecl)fieldNode.get()); + fieldDecl.mods.annotations = fieldDecl.mods.annotations.append(annotationJsonProperty); + } + private void handleJacksonizedBuilder(JavacNode annotationNode, JavacNode annotatedNode, JavacNode tdNode, JCClassDecl td, JavacNode builderAnnotationNode, JavacNode superBuilderAnnotationNode) { if (builderAnnotationNode != null && superBuilderAnnotationNode != null) { annotationNode.addError("@Jacksonized cannot process both @Builder and @SuperBuilder on the same class."); From f5cf267d023bea2d73abb6ce512939252458c9d7 Mon Sep 17 00:00:00 2001 From: Liam Pace <146035497+liampace@users.noreply.github.com> Date: Tue, 30 Sep 2025 11:50:02 -0400 Subject: [PATCH 6/7] Add fields with `@JsonIgore` to test case --- .../JacksonizedAccessorsTransient.java | 42 +++++++++++++++++++ .../JacksonizedAccessorsTransient.java | 26 +++++++++++- .../before/JacksonizedAccessorsTransient.java | 2 + 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/test/transform/resource/after-delombok/JacksonizedAccessorsTransient.java b/test/transform/resource/after-delombok/JacksonizedAccessorsTransient.java index 4db7280c..af6f369d 100644 --- a/test/transform/resource/after-delombok/JacksonizedAccessorsTransient.java +++ b/test/transform/resource/after-delombok/JacksonizedAccessorsTransient.java @@ -1,12 +1,32 @@ public class JacksonizedAccessorsTransient { @com.fasterxml.jackson.annotation.JsonIgnore private transient int intValue; + @com.fasterxml.jackson.annotation.JsonIgnore + private transient long longValue; + @com.fasterxml.jackson.annotation.JsonIgnore + private double doubleValue; + @com.fasterxml.jackson.annotation.JsonIgnore @java.lang.SuppressWarnings("all") @lombok.Generated public int intValue() { return this.intValue; } + + @com.fasterxml.jackson.annotation.JsonIgnore + @java.lang.SuppressWarnings("all") + @lombok.Generated + public long longValue() { + return this.longValue; + } + + @com.fasterxml.jackson.annotation.JsonIgnore + @java.lang.SuppressWarnings("all") + @lombok.Generated + public double doubleValue() { + return this.doubleValue; + } + /** * @return {@code this}. */ @@ -17,4 +37,26 @@ public class JacksonizedAccessorsTransient { this.intValue = intValue; return this; } + + /** + * @return {@code this}. + */ + @com.fasterxml.jackson.annotation.JsonIgnore + @java.lang.SuppressWarnings("all") + @lombok.Generated + public JacksonizedAccessorsTransient longValue(final long longValue) { + this.longValue = longValue; + return this; + } + + /** + * @return {@code this}. + */ + @com.fasterxml.jackson.annotation.JsonIgnore + @java.lang.SuppressWarnings("all") + @lombok.Generated + public JacksonizedAccessorsTransient doubleValue(final double doubleValue) { + this.doubleValue = doubleValue; + return this; + } } \ No newline at end of file diff --git a/test/transform/resource/after-ecj/JacksonizedAccessorsTransient.java b/test/transform/resource/after-ecj/JacksonizedAccessorsTransient.java index ad318f73..b9227f61 100644 --- a/test/transform/resource/after-ecj/JacksonizedAccessorsTransient.java +++ b/test/transform/resource/after-ecj/JacksonizedAccessorsTransient.java @@ -1,16 +1,38 @@ public @lombok.extern.jackson.Jacksonized @lombok.experimental.Accessors(fluent = true) @lombok.Getter @lombok.Setter class JacksonizedAccessorsTransient { private transient @com.fasterxml.jackson.annotation.JsonIgnore int intValue; + private transient @com.fasterxml.jackson.annotation.JsonIgnore long longValue; + private @com.fasterxml.jackson.annotation.JsonIgnore double doubleValue; public JacksonizedAccessorsTransient() { super(); } - public @com.fasterxml.jackson.annotation.JsonIgnore @java.lang.SuppressWarnings("all") @lombok.Generated int intValue() { + public @java.lang.SuppressWarnings("all") @lombok.Generated int intValue() { return this.intValue; } + public @com.fasterxml.jackson.annotation.JsonIgnore @java.lang.SuppressWarnings("all") @lombok.Generated long longValue() { + return this.longValue; + } + public @com.fasterxml.jackson.annotation.JsonIgnore @java.lang.SuppressWarnings("all") @lombok.Generated double doubleValue() { + return this.doubleValue; + } /** * @return {@code this}. */ - public @com.fasterxml.jackson.annotation.JsonIgnore @java.lang.SuppressWarnings("all") @lombok.Generated JacksonizedAccessorsTransient intValue(final int intValue) { + public @java.lang.SuppressWarnings("all") @lombok.Generated JacksonizedAccessorsTransient intValue(final int intValue) { this.intValue = intValue; return this; } + /** + * @return {@code this}. + */ + public @com.fasterxml.jackson.annotation.JsonIgnore @java.lang.SuppressWarnings("all") @lombok.Generated JacksonizedAccessorsTransient longValue(final long longValue) { + this.longValue = longValue; + return this; + } + /** + * @return {@code this}. + */ + public @com.fasterxml.jackson.annotation.JsonIgnore @java.lang.SuppressWarnings("all") @lombok.Generated JacksonizedAccessorsTransient doubleValue(final double doubleValue) { + this.doubleValue = doubleValue; + return this; + } } \ No newline at end of file diff --git a/test/transform/resource/before/JacksonizedAccessorsTransient.java b/test/transform/resource/before/JacksonizedAccessorsTransient.java index 6b04e62c..ca5281f0 100644 --- a/test/transform/resource/before/JacksonizedAccessorsTransient.java +++ b/test/transform/resource/before/JacksonizedAccessorsTransient.java @@ -4,4 +4,6 @@ @lombok.Setter public class JacksonizedAccessorsTransient { private transient int intValue; + @com.fasterxml.jackson.annotation.JsonIgnore private transient long longValue; + @com.fasterxml.jackson.annotation.JsonIgnore private double doubleValue; } \ No newline at end of file From 5ceb5f5e89b27817b4a577a66fae2e04b6c545e5 Mon Sep 17 00:00:00 2001 From: Liam Pace <146035497+liampace@users.noreply.github.com> Date: Tue, 30 Sep 2025 11:50:25 -0400 Subject: [PATCH 7/7] Update handlers to account for pre-existing `@JsonIgnore` annotations --- .../eclipse/handlers/HandleJacksonized.java | 12 ++++++++---- .../lombok/javac/handlers/HandleJacksonized.java | 16 ++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/core/lombok/eclipse/handlers/HandleJacksonized.java b/src/core/lombok/eclipse/handlers/HandleJacksonized.java index b6f5c68a..d148d8b7 100644 --- a/src/core/lombok/eclipse/handlers/HandleJacksonized.java +++ b/src/core/lombok/eclipse/handlers/HandleJacksonized.java @@ -188,15 +188,20 @@ public class HandleJacksonized extends EclipseAnnotationHandler { // Add @JsonProperty to all fields. It will be automatically copied to the getter/setters later. for (EclipseNode eclipseNode : tdNode.down()) { if (eclipseNode.getKind() == Kind.FIELD) { - if (eclipseNode.isTransient()) createJsonIgnoreForField(eclipseNode, annotationNode); - else createJsonPropertyForField(eclipseNode, annotationNode); + if (JacksonAnnotations.JSON_PROPERTY.isAnnotating(eclipseNode) || + JacksonAnnotations.JSON_IGNORE.isAnnotating(eclipseNode)) { + return; + } else if (eclipseNode.isTransient()) { + createJsonIgnoreForField(eclipseNode, annotationNode); + } else { + createJsonPropertyForField(eclipseNode, annotationNode); + } } } tdNode.rebuild(); } private void createJsonPropertyForField(EclipseNode fieldNode, EclipseNode annotationNode) { - if (JacksonAnnotations.JSON_PROPERTY.isAnnotating(fieldNode)) return; ASTNode astNode = fieldNode.get(); if (astNode instanceof FieldDeclaration) { FieldDeclaration fd = (FieldDeclaration)astNode; @@ -206,7 +211,6 @@ public class HandleJacksonized extends EclipseAnnotationHandler { } private void createJsonIgnoreForField(EclipseNode fieldNode, EclipseNode annotationNode) { - if (JacksonAnnotations.JSON_IGNORE.isAnnotating(fieldNode)) return; ASTNode astNode = fieldNode.get(); if (astNode instanceof FieldDeclaration) { FieldDeclaration fd = (FieldDeclaration)astNode; diff --git a/src/core/lombok/javac/handlers/HandleJacksonized.java b/src/core/lombok/javac/handlers/HandleJacksonized.java index 6a43abe4..7cfabfed 100644 --- a/src/core/lombok/javac/handlers/HandleJacksonized.java +++ b/src/core/lombok/javac/handlers/HandleJacksonized.java @@ -122,16 +122,19 @@ public class HandleJacksonized extends JavacAnnotationHandler { // Add @JsonIgnore to all transient fields. It will be automatically copied to the getter/setters later. for (JavacNode javacNode : tdNode.down()) { if (javacNode.getKind() == Kind.FIELD) { - if (javacNode.isTransient()) createJsonIgnoreForField(javacNode, annotationNode); - else createJsonPropertyForField(javacNode, annotationNode); + if (JacksonAnnotations.JSON_PROPERTY.isAnnotating(javacNode) || + JacksonAnnotations.JSON_IGNORE.isAnnotating(javacNode)) { + return; + } else if (javacNode.isTransient()) { + createJsonIgnoreForField(javacNode, annotationNode); + } else { + createJsonPropertyForField(javacNode, annotationNode); + } } } } private void createJsonPropertyForField(JavacNode fieldNode, JavacNode annotationNode) { - if (JacksonAnnotations.JSON_PROPERTY.isAnnotating(fieldNode)) { - return; - } JavacTreeMaker maker = fieldNode.getTreeMaker(); JCExpression jsonPropertyType = chainDots(fieldNode, JacksonAnnotations.JSON_PROPERTY.chainedDots); @@ -142,9 +145,6 @@ public class HandleJacksonized extends JavacAnnotationHandler { } private void createJsonIgnoreForField(JavacNode fieldNode, JavacNode annotationNode) { - if (JacksonAnnotations.JSON_IGNORE.isAnnotating(fieldNode)) { - return; - } JavacTreeMaker maker = fieldNode.getTreeMaker(); JCExpression jsonPropertyType = chainDots(fieldNode, JacksonAnnotations.JSON_IGNORE.chainedDots);