mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 18:18:48 +00:00
also include getters, rename to copyJacksonAnnotationsToAccessors
This commit is contained in:
1 parent
93d8169f50
commit
592882feef
6 files changed
+28
-10
No files matched your search
@@ -746,10 +746,10 @@ public class ConfigurationKeys {
|
||||
public static final ConfigurationKey<FlagUsageType> STANDARD_EXCEPTION_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.standardException.flagUsage", "Emit a warning or error if @StandardException is used.") {};
|
||||
|
||||
/**
|
||||
* lombok configuration: {@code lombok.copyJacksonAnnotationsToSetters} = {@code true} | {@code false}.
|
||||
* lombok configuration: {@code lombok.copyJacksonAnnotationsToAccessors} = {@code true} | {@code false}.
|
||||
*
|
||||
* If <code>true</code>, copy certain Jackson annotations from a field to its corresponding getter. This was the behavior from lombok 1.18.16 to 1.18.38.
|
||||
* If <code>true</code>, copy certain Jackson annotations from a field to its corresponding accessors (getter/setters). This was the behavior from lombok 1.18.16 to 1.18.38.
|
||||
* However, it turned out to be harmful in certain situations. Thus, the default is now <code>false</code>.
|
||||
*/
|
||||
public static final ConfigurationKey<Boolean> COPY_JACKSON_ANNOTATIONS_TO_SETTERS = new ConfigurationKey<Boolean>("lombok.copyJacksonAnnotationsToSetters", "Copy these annotations to getters, setters, with methods, builder-setters, etc.") {};
|
||||
public static final ConfigurationKey<Boolean> COPY_JACKSON_ANNOTATIONS_TO_ACCESSORS = new ConfigurationKey<Boolean>("lombok.copyJacksonAnnotationsToAccessors", "Copy Jackson annotations from fields to their getters and setters.") {};
|
||||
}
|
||||
@@ -822,7 +822,11 @@ public class EclipseHandlerUtil {
|
||||
/**
|
||||
* Searches the given field node for annotations that are specifically intentioned to be copied to the setter.
|
||||
*/
|
||||
public static Annotation[] findCopyableToGetterAnnotations(EclipseNode node) {
|
||||
public static Annotation[] findCopyableToGetterAnnotations(EclipseNode node, boolean forceCopyJacksonAnnotations) {
|
||||
if (!forceCopyJacksonAnnotations) {
|
||||
Boolean copyAnnotations = node.getAst().readConfiguration(ConfigurationKeys.COPY_JACKSON_ANNOTATIONS_TO_ACCESSORS);
|
||||
if (copyAnnotations == null || !copyAnnotations) return EMPTY_ANNOTATIONS_ARRAY;
|
||||
}
|
||||
return findAnnotationsInList(node, JACKSON_COPY_TO_GETTER_ANNOTATIONS);
|
||||
}
|
||||
|
||||
@@ -833,7 +837,7 @@ public class EclipseHandlerUtil {
|
||||
*/
|
||||
public static Annotation[] findCopyableToSetterAnnotations(EclipseNode node, boolean forceCopyJacksonAnnotations) {
|
||||
if (!forceCopyJacksonAnnotations) {
|
||||
Boolean copyAnnotations = node.getAst().readConfiguration(ConfigurationKeys.COPY_JACKSON_ANNOTATIONS_TO_SETTERS);
|
||||
Boolean copyAnnotations = node.getAst().readConfiguration(ConfigurationKeys.COPY_JACKSON_ANNOTATIONS_TO_ACCESSORS);
|
||||
if (copyAnnotations == null || !copyAnnotations) return EMPTY_ANNOTATIONS_ARRAY;
|
||||
}
|
||||
return findAnnotationsInList(node, JACKSON_COPY_TO_SETTER_ANNOTATIONS);
|
||||
|
||||
@@ -281,10 +281,15 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> {
|
||||
if (getCheckerFrameworkVersion(fieldNode).generateSideEffectFree()) checkerFramework = new Annotation[] { generateNamedAnnotation(source, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE) };
|
||||
}
|
||||
|
||||
// Copying Jackson annotations is required for fluent accessors (otherwise Jackson would not find the accessor).
|
||||
boolean fluent = accessors.isExplicit("fluent");
|
||||
Boolean fluentConfig = fieldNode.getAst().readConfiguration(ConfigurationKeys.ACCESSORS_FLUENT);
|
||||
if (fluentConfig != null && fluentConfig) fluent = fluentConfig;
|
||||
|
||||
method.annotations = copyAnnotations(source,
|
||||
onMethod.toArray(new Annotation[0]),
|
||||
findCopyableAnnotations(fieldNode),
|
||||
findCopyableToGetterAnnotations(fieldNode),
|
||||
findCopyableToGetterAnnotations(fieldNode, fluent),
|
||||
findDelegatesAndMarkAsHandled(fieldNode),
|
||||
checkerFramework,
|
||||
deprecated);
|
||||
|
||||
@@ -252,7 +252,12 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
|
||||
JCExpression annotationMethodDefaultValue = null;
|
||||
|
||||
List<JCAnnotation> copyableAnnotations = findCopyableAnnotations(field);
|
||||
List<JCAnnotation> copyableToGetterAnnotations = copyAnnotations(findCopyableToGetterAnnotations(field), treeMaker);
|
||||
|
||||
// Copying Jackson annotations is required for fluent accessors (otherwise Jackson would not find the accessor).
|
||||
boolean fluent = accessors.isExplicit("fluent");
|
||||
Boolean fluentConfig = field.getAst().readConfiguration(ConfigurationKeys.ACCESSORS_FLUENT);
|
||||
if (fluentConfig != null && fluentConfig) fluent = fluentConfig;
|
||||
List<JCAnnotation> copyableToGetterAnnotations = copyAnnotations(findCopyableToGetterAnnotations(field, fluent), treeMaker);
|
||||
|
||||
List<JCAnnotation> delegates = findDelegatesAndRemoveFromField(field);
|
||||
List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod, treeMaker).appendList(copyableAnnotations).appendList(copyableToGetterAnnotations);
|
||||
|
||||
@@ -1759,7 +1759,11 @@ public class JavacHandlerUtil {
|
||||
/**
|
||||
* Searches the given field node for annotations that are specifically intentioned to be copied to the getter.
|
||||
*/
|
||||
public static List<JCAnnotation> findCopyableToGetterAnnotations(JavacNode node) {
|
||||
public static List<JCAnnotation> findCopyableToGetterAnnotations(JavacNode node, boolean forceCopyJacksonAnnotations) {
|
||||
if (!forceCopyJacksonAnnotations) {
|
||||
Boolean copyAnnotations = node.getAst().readConfiguration(ConfigurationKeys.COPY_JACKSON_ANNOTATIONS_TO_ACCESSORS);
|
||||
if (copyAnnotations == null || !copyAnnotations) return List.nil();
|
||||
}
|
||||
return findAnnotationsInList(node, JACKSON_COPY_TO_GETTER_ANNOTATIONS);
|
||||
}
|
||||
|
||||
@@ -1770,7 +1774,7 @@ public class JavacHandlerUtil {
|
||||
*/
|
||||
public static List<JCAnnotation> findCopyableToSetterAnnotations(JavacNode node, boolean forceCopyJacksonAnnotations) {
|
||||
if (!forceCopyJacksonAnnotations) {
|
||||
Boolean copyAnnotations = node.getAst().readConfiguration(ConfigurationKeys.COPY_JACKSON_ANNOTATIONS_TO_SETTERS);
|
||||
Boolean copyAnnotations = node.getAst().readConfiguration(ConfigurationKeys.COPY_JACKSON_ANNOTATIONS_TO_ACCESSORS);
|
||||
if (copyAnnotations == null || !copyAnnotations) return List.nil();
|
||||
}
|
||||
return findAnnotationsInList(node, JACKSON_COPY_TO_SETTER_ANNOTATIONS);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//CONF: lombok.copyJacksonAnnotationsToSetters = true
|
||||
//CONF: lombok.copyJacksonAnnotationsToAccessors = true
|
||||
//version 8: Jackson deps are at least Java7+.
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
|
||||
Reference in new issue
Block a user