Skip to content

Commit 3a49c0a

Browse files
committed
Remove redundant @JsonIgnore annotation
1 parent c1a3c45 commit 3a49c0a

File tree

4 files changed

+10
-37
lines changed

4 files changed

+10
-37
lines changed

src/core/lombok/eclipse/handlers/HandleJacksonized.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ private void handleJacksonizedAccessors(Annotation ast, EclipseNode annotationNo
187187

188188
// Add @JsonProperty to all fields. It will be automatically copied to the getter/setters later.
189189
for (EclipseNode eclipseNode : tdNode.down()) {
190-
if (eclipseNode.getKind() == Kind.FIELD) {
191-
if (eclipseNode.isTransient()) createJsonIgnoreForField(eclipseNode, annotationNode);
192-
else createJsonPropertyForField(eclipseNode, annotationNode);
190+
if (eclipseNode.getKind() != Kind.FIELD || eclipseNode.isTransient()) {
191+
continue;
193192
}
193+
createJsonPropertyForField(eclipseNode, annotationNode);
194194
}
195195
tdNode.rebuild();
196196
}
@@ -205,15 +205,6 @@ private void createJsonPropertyForField(EclipseNode fieldNode, EclipseNode annot
205205
}
206206
}
207207

208-
private void createJsonIgnoreForField(EclipseNode fieldNode, EclipseNode annotationNode) {
209-
if (JacksonAnnotations.JSON_IGNORE.isAnnotating(fieldNode)) return;
210-
ASTNode astNode = fieldNode.get();
211-
if (astNode instanceof FieldDeclaration) {
212-
FieldDeclaration fd = (FieldDeclaration)astNode;
213-
((FieldDeclaration) astNode).annotations = addAnnotation(fieldNode.get(), fd.annotations, JacksonAnnotations.JSON_IGNORE.annotation);
214-
}
215-
}
216-
217208
private String getBuilderClassName(Annotation ast, EclipseNode annotationNode, EclipseNode annotatedNode, TypeDeclaration td, AnnotationValues<Builder> builderAnnotation) {
218209
String builderClassName = builderAnnotation != null ?
219210
builderAnnotation.getInstance().builderClassName() : null;

src/core/lombok/javac/handlers/HandleJacksonized.java

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> {
6363
private static enum JacksonAnnotations {
6464
JSON_POJO_BUILDER("com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder"),
6565
JSON_DESERIALIZE("com.fasterxml.jackson.databind.annotation.JsonDeserialize"),
66-
JSON_PROPERTY("com.fasterxml.jackson.annotation.JsonProperty"),
67-
JSON_IGNORE("com.fasterxml.jackson.annotation.JsonIgnore");
66+
JSON_PROPERTY("com.fasterxml.jackson.annotation.JsonProperty");
6867

6968
private final String qualifiedName;
7069
private final String[] chainedDots;
@@ -119,12 +118,11 @@ private void handleJacksonizedAccessors(JavacNode annotationNode, JavacNode anno
119118
}
120119

121120
// Add @JsonProperty to all non-transient fields. It will be automatically copied to the getter/setters later.
122-
// Add @JsonIgnore to all transient fields. It will be automatically copied to the getter/setters later.
123121
for (JavacNode javacNode : tdNode.down()) {
124-
if (javacNode.getKind() == Kind.FIELD) {
125-
if (javacNode.isTransient()) createJsonIgnoreForField(javacNode, annotationNode);
126-
else createJsonPropertyForField(javacNode, annotationNode);
122+
if (javacNode.getKind() != Kind.FIELD || javacNode.isTransient()) {
123+
continue;
127124
}
125+
createJsonPropertyForField(javacNode, annotationNode);
128126
}
129127
}
130128

@@ -141,19 +139,6 @@ private void createJsonPropertyForField(JavacNode fieldNode, JavacNode annotatio
141139
fieldDecl.mods.annotations = fieldDecl.mods.annotations.append(annotationJsonProperty);
142140
}
143141

144-
private void createJsonIgnoreForField(JavacNode fieldNode, JavacNode annotationNode) {
145-
if (JacksonAnnotations.JSON_IGNORE.isAnnotating(fieldNode)) {
146-
return;
147-
}
148-
JavacTreeMaker maker = fieldNode.getTreeMaker();
149-
150-
JCExpression jsonPropertyType = chainDots(fieldNode, JacksonAnnotations.JSON_IGNORE.chainedDots);
151-
JCAnnotation annotationJsonProperty = maker.Annotation(jsonPropertyType, List.<JCExpression>nil());
152-
recursiveSetGeneratedBy(annotationJsonProperty, annotationNode);
153-
JCVariableDecl fieldDecl = ((JCVariableDecl)fieldNode.get());
154-
fieldDecl.mods.annotations = fieldDecl.mods.annotations.append(annotationJsonProperty);
155-
}
156-
157142
private void handleJacksonizedBuilder(JavacNode annotationNode, JavacNode annotatedNode, JavacNode tdNode, JCClassDecl td, JavacNode builderAnnotationNode, JavacNode superBuilderAnnotationNode) {
158143
if (builderAnnotationNode != null && superBuilderAnnotationNode != null) {
159144
annotationNode.addError("@Jacksonized cannot process both @Builder and @SuperBuilder on the same class.");

test/transform/resource/after-delombok/JacksonizedAccessorsTransient.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
public class JacksonizedAccessorsTransient {
2-
@com.fasterxml.jackson.annotation.JsonIgnore
32
private transient int intValue;
4-
@com.fasterxml.jackson.annotation.JsonIgnore
53
@java.lang.SuppressWarnings("all")
64
@lombok.Generated
75
public int intValue() {
@@ -10,7 +8,6 @@ public int intValue() {
108
/**
119
* @return {@code this}.
1210
*/
13-
@com.fasterxml.jackson.annotation.JsonIgnore
1411
@java.lang.SuppressWarnings("all")
1512
@lombok.Generated
1613
public JacksonizedAccessorsTransient intValue(final int intValue) {

test/transform/resource/after-ecj/JacksonizedAccessorsTransient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
public @lombok.extern.jackson.Jacksonized @lombok.experimental.Accessors(fluent = true) @lombok.Getter @lombok.Setter class JacksonizedAccessorsTransient {
2-
private transient @com.fasterxml.jackson.annotation.JsonIgnore int intValue;
2+
private transient int intValue;
33
public JacksonizedAccessorsTransient() {
44
super();
55
}
6-
public @com.fasterxml.jackson.annotation.JsonIgnore @java.lang.SuppressWarnings("all") @lombok.Generated int intValue() {
6+
public @java.lang.SuppressWarnings("all") @lombok.Generated int intValue() {
77
return this.intValue;
88
}
99
/**
1010
* @return {@code this}.
1111
*/
12-
public @com.fasterxml.jackson.annotation.JsonIgnore @java.lang.SuppressWarnings("all") @lombok.Generated JacksonizedAccessorsTransient intValue(final int intValue) {
12+
public @java.lang.SuppressWarnings("all") @lombok.Generated JacksonizedAccessorsTransient intValue(final int intValue) {
1313
this.intValue = intValue;
1414
return this;
1515
}

0 commit comments

Comments
 (0)