[jacksonized] infrastructure for previous merge resolution: Changed to the config system so you can specify jackson major version, or even multiple versions.

This commit is contained in:
Reinier Zwitserloot committed 2026-02-06 00:23:14 +01:00
1 parent d62b2d5b80
commit d441be157b
7 files changed
+163 -71

No files matched your search

+10 -9
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2025 The Project Lombok Authors.
* Copyright (C) 2013-2026 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
@@ -702,7 +702,7 @@ public class ConfigurationKeys {
* If set, <em>any</em> usage of {@code @WithBy} results in a warning / error.
*/
public static final ConfigurationKey<FlagUsageType> WITHBY_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.withBy.flagUsage", "Emit a warning or error if @WithBy is used.") {};
// ----- Jacksonized -----
/**
@@ -712,15 +712,16 @@ public class ConfigurationKeys {
*/
public static final ConfigurationKey<FlagUsageType> JACKSONIZED_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.jacksonized.flagUsage", "Emit a warning or error if @Jacksonized is used.") {};
/**
* lombok configuration: {@code lombok.jacksonized.jacksonVersion} = {@code 2} | {@code 3} | {@code 2_3}.
*
* The jackson major version to use.
* lombok configuration: {@code lombok.jacksonized.jacksonVersion} += {@code 2} / {@code 3}.
*
* Which version of the jackson annotations to generate.
*
* If no values specified: Generate version 2 and emit a warning to explicitly choose a jackson version in your {@code lombok.config}.
*/
public static final ConfigurationKey<JacksonVersion> JACKSONIZED_JACKSON_VERSION = new ConfigurationKey<JacksonVersion>("lombok.jacksonized.jacksonVersion", "Select the jackson major version to use (default: 2)") {};
public static final ConfigurationKey<List<JacksonVersion>> JACKSONIZED_JACKSON_VERSION = new ConfigurationKey<List<JacksonVersion>>("lombok.jacksonized.jacksonVersion", "The jackson major version(s) to generate (default: 2 + warning)") {};
// ----- Configuration System -----
/**
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2026 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.core;
public enum JacksonAnnotationType {
JSON_POJO_BUILDER2("com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder"),
JSON_POJO_BUILDER3("tools.jackson.databind.annotation.JsonPOJOBuilder"),
JSON_DESERIALIZE2("com.fasterxml.jackson.databind.annotation.JsonDeserialize"),
JSON_DESERIALIZE3("tools.jackson.databind.annotation.JsonDeserialize"),
JSON_PROPERTY2("com.fasterxml.jackson.annotation.JsonProperty"),
JSON_IGNORE2("com.fasterxml.jackson.annotation.JsonIgnore"),
;
private final String qualifiedName;
private final String[] qualifiedNameStringArr;
private final char[][] qualifiedNameCharArrArr;
private JacksonAnnotationType(final String qualifiedName) {
this.qualifiedName = qualifiedName;
String[] parts = qualifiedName.split("\\.");
this.qualifiedNameStringArr = parts;
char[][] caa = new char[parts.length][];
for (int i = 0; i < parts.length; i++) {
caa[i] = parts[i].toCharArray();
}
this.qualifiedNameCharArrArr = caa;
}
public String getQualifiedName() {
return qualifiedName;
}
// Do not modify the returned array.
public String[] getQualifiedNameAsStringArray() {
return qualifiedNameStringArr;
}
// Do not modify the returned array.
public char[][] getQualifiednameAsCharArrayArray() {
return qualifiedNameCharArrArr;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2019 The Project Lombok Authors.
* Copyright (C) 2013-2026 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
@@ -102,23 +102,30 @@ public final class ConfigurationDataType {
SIMPLE_TYPES = map;
}
private static ConfigurationValueParser enumParser(Type enumType) {
private static ConfigurationValueParser enumParser(final Type enumType) {
final Class<?> type = (Class<?>) enumType;
@SuppressWarnings("rawtypes") final Class rawType = type;
return new ConfigurationValueParser() {
@SuppressWarnings("unchecked")
@Override public Object parse(String value) {
try {
return Enum.valueOf(rawType, value);
} catch (Exception e) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (Character.isUpperCase(c) && i > 0) sb.append("_");
sb.append(Character.toUpperCase(c));
if (enumType instanceof Class<?> && MappedConfigEnum.class.isAssignableFrom(type)) {
for (Object enumVal : ((Class<?>) enumType).getEnumConstants()) {
if (((MappedConfigEnum) enumVal).matches(value)) return enumVal;
}
throw new IllegalArgumentException("Invalid value: " + value);
} else {
try {
return Enum.valueOf(rawType, value);
} catch (Exception e) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (Character.isUpperCase(c) && i > 0) sb.append("_");
sb.append(Character.toUpperCase(c));
}
return Enum.valueOf(rawType, sb.toString());
}
return Enum.valueOf(rawType, sb.toString());
}
}
@@ -129,7 +136,7 @@ public final class ConfigurationDataType {
@Override public String exampleValue() {
ExampleValueString evs = type.getAnnotation(ExampleValueString.class);
if (evs != null) return evs.value();
return Arrays.toString(type.getEnumConstants()).replace(",", " |");
return Arrays.toString(type.getEnumConstants()).replace(",", " | ");
}
};
}
@@ -1,54 +1,38 @@
/*
* Copyright (C) 2026 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.core.configuration;
public final class JacksonVersion implements ConfigurationValueType {
private final boolean useJackson2;
private final boolean useJackson3;
private static final JacksonVersion _2 = new JacksonVersion(true, false);
private static final JacksonVersion _3 = new JacksonVersion(false, true);
private static final JacksonVersion _23 = new JacksonVersion(true, true);
public static final JacksonVersion getDefault() {
return _2;
public enum JacksonVersion implements MappedConfigEnum {
TWO,
THREE,
;
@Override public boolean matches(String value) {
if (this == TWO) return "2".equals(value);
return "3".equals(value);
}
public static String exampleValue() {
return "2, 3 or 2_3";
}
public static String description() {
return "Select the major version of the jackson framework.";
}
public static JacksonVersion valueOf(String value) {
if (value == null || value.isEmpty()) {
return getDefault();
} else if ("2".equals(value.trim())) {
return _2;
} else if ("3".equals(value.trim())) {
return _3;
} else if ("2_3".equals(value.trim())) {
return _23;
} else {
throw new IllegalArgumentException("Unsupported Jackson version selector.");
}
}
private JacksonVersion(boolean useJackson2, boolean useJackson3) {
this.useJackson2 = useJackson2;
this.useJackson3 = useJackson3;
}
public boolean useJackson2() {
return useJackson2;
}
public boolean useJackson3() {
return useJackson3;
}
public boolean isValid() {
return useJackson2 || useJackson3;
@Override public String toString() {
if (this == TWO) return "2";
return "3";
}
}
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2026 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.core.configuration;
public interface MappedConfigEnum {
boolean matches(String value);
}
@@ -47,7 +47,6 @@ import lombok.core.JacksonAnnotationType;
import lombok.core.AST.Kind;
import lombok.core.configuration.JacksonVersion;
import lombok.core.handlers.HandlerUtil;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
import lombok.eclipse.EclipseNode;
import lombok.experimental.Accessors;
@@ -39,6 +39,20 @@ public class JacksonExample {
</p>
</@f.overview>
<@f.confKeys>
<dt>
<code>lombok.jacksonized.flagUsage</code> = [<code>warning</code> | <code>error</code>] (default: not set)
</dt><dd>
Lombok will flag any usage of <code>@Jacksonized</code> as a warning or error if configured.
</dd><dt>
<code>lombok.jacksonized.jacksonVersion</code> += <code>version</code> (default: 2 + generate warning)
</dt><dd>
(Since 1.18.44) Jackson now has 2 different major versions: Jackson2, and Jackson3. Specify which version of the jackson annotations to generate.<br />
If no version is chosen, lombok will generate Jackson v2 annotations and emit a warning that you should add this config key to pick which jackson version you want.<br />
If transitioning from Jackson2 to Jackson3, you can ask lombok to emit both variants. See: <a href="/features/configuration">Lombok configuration system</a>.
</dd>
</@f.confKeys>
<@f.smallPrint>
<p>
In particular, the annotation does the following for <code>@(Super)Builder</code>: