From 290fa4c8539c7e97b47f7e80033e078127050eb5 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 22 Apr 2026 00:48:26 +0200 Subject: [PATCH] [trivial] constantize the warning we spit out for ambiguous jackson2/3, and match style to lombok project style. --- src/core/lombok/core/configuration/JacksonVersion.java | 3 +++ src/core/lombok/eclipse/handlers/HandleJacksonized.java | 8 ++++---- src/core/lombok/javac/handlers/HandleJacksonized.java | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/core/lombok/core/configuration/JacksonVersion.java b/src/core/lombok/core/configuration/JacksonVersion.java index 58a5e52c..480dd973 100644 --- a/src/core/lombok/core/configuration/JacksonVersion.java +++ b/src/core/lombok/core/configuration/JacksonVersion.java @@ -26,6 +26,9 @@ public enum JacksonVersion implements MappedConfigEnum { THREE, ; + public static final String AMBIGUOUS_JACKSON_VERSION_WARNING_TEXT = + "Ambiguous: Jackson2 and Jackson3 exist; define which variant(s) you want in 'lombok.config'. See https://projectlombok.org/features/experimental/Jacksonized"; + @Override public boolean matches(String value) { if (this == TWO) return "2".equals(value); return "3".equals(value); diff --git a/src/core/lombok/eclipse/handlers/HandleJacksonized.java b/src/core/lombok/eclipse/handlers/HandleJacksonized.java index cd8821d5..a1f34df9 100644 --- a/src/core/lombok/eclipse/handlers/HandleJacksonized.java +++ b/src/core/lombok/eclipse/handlers/HandleJacksonized.java @@ -188,7 +188,7 @@ 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 (hasAnnotation(eclipseNode, JacksonAnnotationType.JSON_PROPERTY2) || + if (hasAnnotation(eclipseNode, JacksonAnnotationType.JSON_PROPERTY2) || hasAnnotation(eclipseNode, JacksonAnnotationType.JSON_IGNORE2)) { continue; } @@ -210,7 +210,7 @@ public class HandleJacksonized extends EclipseAnnotationHandler { fd.annotations = addAnnotation(fieldNode.get(), fd.annotations, JacksonAnnotationType.JSON_PROPERTY2.getQualifiednameAsCharArrayArray(), fieldName); } } - + private void createJsonIgnoreForField(EclipseNode fieldNode, EclipseNode annotationNode) { ASTNode astNode = fieldNode.get(); if (astNode instanceof FieldDeclaration) { @@ -218,7 +218,7 @@ public class HandleJacksonized extends EclipseAnnotationHandler { fd.annotations = addAnnotation(fieldNode.get(), fd.annotations, JacksonAnnotationType.JSON_IGNORE2.getQualifiednameAsCharArrayArray()); } } - + private String getBuilderClassName(Annotation ast, EclipseNode annotationNode, EclipseNode annotatedNode, TypeDeclaration td, AnnotationValues builderAnnotation) { String builderClassName = builderAnnotation != null ? builderAnnotation.getInstance().builderClassName() : null; @@ -246,7 +246,7 @@ public class HandleJacksonized extends EclipseAnnotationHandler { private List readConfiguredJacksonVersions(EclipseNode annotationNode) { List jacksonVersions = annotationNode.getAst().readConfigurationOr(ConfigurationKeys.JACKSONIZED_JACKSON_VERSION, Arrays.asList()); if (!jacksonVersions.isEmpty()) return jacksonVersions; - annotationNode.addWarning("Ambiguous: Jackson2 and Jackson3 exist; define which variant(s) you want in 'lombok.config'. See https://projectlombok.org/features/experimental/Jacksonized"); + annotationNode.addWarning(JacksonVersion.AMBIGUOUS_JACKSON_VERSION_WARNING_TEXT); return Arrays.asList(JacksonVersion.TWO); } diff --git a/src/core/lombok/javac/handlers/HandleJacksonized.java b/src/core/lombok/javac/handlers/HandleJacksonized.java index a8b8555a..b2e2a9b7 100644 --- a/src/core/lombok/javac/handlers/HandleJacksonized.java +++ b/src/core/lombok/javac/handlers/HandleJacksonized.java @@ -135,11 +135,11 @@ public class HandleJacksonized extends JavacAnnotationHandler { List args = List.of(maker.Literal(fieldNode.getName())); addFieldAnnotation(fieldNode, annotationNode, JacksonAnnotationType.JSON_PROPERTY2, args); } - + private void createJsonIgnoreForField(JavacNode fieldNode, JavacNode annotationNode) { addFieldAnnotation(fieldNode, annotationNode, JacksonAnnotationType.JSON_IGNORE2, List.nil()); } - + private void addFieldAnnotation(JavacNode fieldNode, JavacNode annotationNode, JacksonAnnotationType annotationType, List args) { JavacTreeMaker maker = fieldNode.getTreeMaker(); JCExpression type = chainDots(fieldNode, annotationType); @@ -192,7 +192,7 @@ public class HandleJacksonized extends JavacAnnotationHandler { } Collection jacksonVersions = readConfiguredJacksonVersions(annotationNode); - + // Insert @JsonDeserialize on annotated class. if (hasAnnotation(tdNode, JacksonAnnotationType.JSON_DESERIALIZE2) || hasAnnotation(tdNode, JacksonAnnotationType.JSON_DESERIALIZE3)) { annotationNode.addError("@JsonDeserialize already exists on class. Either delete @JsonDeserialize, or remove @Jacksonized and manually configure Jackson."); @@ -278,7 +278,7 @@ public class HandleJacksonized extends JavacAnnotationHandler { private Collection readConfiguredJacksonVersions(JavacNode annotationNode) { Collection jacksonVersions = annotationNode.getAst().readConfigurationOr(ConfigurationKeys.JACKSONIZED_JACKSON_VERSION, Arrays.asList()); if (!jacksonVersions.isEmpty()) return jacksonVersions; - annotationNode.addWarning("Ambiguous: Jackson2 and Jackson3 exist; define which variant(s) you want in 'lombok.config'. See https://projectlombok.org/features/experimental/Jacksonized"); + annotationNode.addWarning(JacksonVersion.AMBIGUOUS_JACKSON_VERSION_WARNING_TEXT); return Arrays.asList(JacksonVersion.TWO); }