mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 16:17:34 +00:00
copy Jackson annotations to the plural builder setter method
This commit is contained in:
1 parent
66a6c5a883
commit
26c7ad1eb0
7 files changed
+9
-7
No files matched your search
@@ -747,7 +747,7 @@ public class ConfigurationKeys {
|
||||
/**
|
||||
* lombok configuration: {@code lombok.copyJacksonAnnotationsToSetters} = {@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.36.
|
||||
* 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.
|
||||
* 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.") {};
|
||||
|
||||
@@ -829,10 +829,10 @@ public class EclipseHandlerUtil {
|
||||
/**
|
||||
* Searches the given field node for annotations that are specifically intentioned to be copied to the setter.
|
||||
*
|
||||
* @param forceCopy If <code>true</code>, always copy the annotations regardless of the lombok configuration.
|
||||
* @param forceCopyJacksonAnnotations If <code>true</code>, always copy the annotations regardless of the lombok configuration.
|
||||
*/
|
||||
public static Annotation[] findCopyableToSetterAnnotations(EclipseNode node, boolean forceCopy) {
|
||||
if (!forceCopy) {
|
||||
public static Annotation[] findCopyableToSetterAnnotations(EclipseNode node, boolean forceCopyJacksonAnnotations) {
|
||||
if (!forceCopyJacksonAnnotations) {
|
||||
Boolean copyAnnotations = node.getAst().readConfiguration(ConfigurationKeys.COPY_JACKSON_ANNOTATIONS_TO_SETTERS);
|
||||
if (copyAnnotations == null || !copyAnnotations) return EMPTY_ANNOTATIONS_ARRAY;
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
|
||||
|
||||
// If a fluent setter should be generated, force-copy annotations from the field.
|
||||
AnnotationValues<Accessors> accessorsForField = EclipseHandlerUtil.getAccessorsForField(fieldNode);
|
||||
// Copying Jackson annotations is required for fluent accessors (otherwise Jackson would not find the accessor).
|
||||
Annotation[] copyableToSetterAnnotations = findCopyableToSetterAnnotations(fieldNode, accessorsForField.isExplicit("fluent"));
|
||||
onMethod = new ArrayList<Annotation>(onMethod);
|
||||
onMethod.addAll(Arrays.asList(copyableToSetterAnnotations));
|
||||
|
||||
@@ -219,7 +219,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer {
|
||||
char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray();
|
||||
md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName(builderType, "addAll", new String(data.getPluralName())).toCharArray();
|
||||
Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, data.getSource());
|
||||
Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up(), false));
|
||||
Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up(), true));
|
||||
md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class);
|
||||
|
||||
if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md);
|
||||
|
||||
@@ -195,7 +195,7 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula
|
||||
char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray();
|
||||
md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName(builderType, "addAll", new String(data.getPluralName())).toCharArray();
|
||||
Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, data.getSource());
|
||||
Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up(), false));
|
||||
Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up(), true));
|
||||
md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class);
|
||||
|
||||
if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md);
|
||||
|
||||
@@ -332,7 +332,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer
|
||||
|
||||
md.selector = setterName.toCharArray();
|
||||
Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, data.getSource());
|
||||
Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up(), false));
|
||||
Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up(), true));
|
||||
md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class);
|
||||
|
||||
if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//CONF: lombok.copyJacksonAnnotationsToSetters = 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