@@ -31,10 +31,12 @@ private enum GenerateAnnotation {
31
31
QualifiedName .of ("com.fasterxml.jackson.annotation" , "JsonProperty" );
32
32
private static final String JACKSON_XML_ANNOTATION_PACKAGE =
33
33
"com.fasterxml.jackson.dataformat.xml.annotation" ;
34
+ private static final String JSON_ALIAS =
35
+ "com.fasterxml.jackson.annotation.JsonAlias" ;
34
36
private static final QualifiedName JSON_ANY_GETTER =
35
- QualifiedName .of ("com.fasterxml.jackson.annotation" , "JsonAnyGetter" );
37
+ QualifiedName .of ("com.fasterxml.jackson.annotation" , "JsonAnyGetter" );
36
38
private static final QualifiedName JSON_ANY_SETTER =
37
- QualifiedName .of ("com.fasterxml.jackson.annotation" , "JsonAnySetter" );
39
+ QualifiedName .of ("com.fasterxml.jackson.annotation" , "JsonAnySetter" );
38
40
/** Annotations which disable automatic generation of JsonProperty annotations. */
39
41
private static final Set <QualifiedName > DISABLE_PROPERTY_ANNOTATIONS = ImmutableSet .of (
40
42
QualifiedName .of ("com.fasterxml.jackson.annotation" , "JsonIgnore" ),
@@ -55,15 +57,15 @@ private JacksonSupport(Elements elements) {
55
57
public void addJacksonAnnotations (
56
58
Property .Builder resultBuilder ,
57
59
ExecutableElement getterMethod ) {
58
- Optional <AnnotationMirror > jsonPropertyAnnotation = findAnnotationMirror ( getterMethod ,
59
- JSON_PROPERTY );
60
+ Optional <AnnotationMirror > jsonPropertyAnnotation =
61
+ findAnnotationMirror ( getterMethod , JSON_PROPERTY );
60
62
if (jsonPropertyAnnotation .isPresent ()) {
61
63
resultBuilder .addAccessorAnnotations (Excerpts .add ("%s%n" , jsonPropertyAnnotation .get ()));
62
64
} else {
63
65
switch (generateDefaultAnnotations (getterMethod )) {
64
66
case DEFAULT :
65
- resultBuilder .addAccessorAnnotations (Excerpts . add (
66
- "@%s(\" %s\" )%n" , JSON_PROPERTY , resultBuilder .getName ()));
67
+ resultBuilder .addAccessorAnnotations (
68
+ Excerpts . add ( "@%s(\" %s\" )%n" , JSON_PROPERTY , resultBuilder .getName ()));
67
69
break ;
68
70
case JSON_ANY :
69
71
resultBuilder .addPutAnnotations (Excerpts .add ("@%s%n" , JSON_ANY_SETTER ));
@@ -78,15 +80,18 @@ public void addJacksonAnnotations(
78
80
getterMethod
79
81
.getAnnotationMirrors ()
80
82
.stream ()
81
- .filter (this ::isXmlAnnotation )
83
+ .filter (this ::shouldCopyAnnotation )
82
84
.forEach (annotation -> {
83
- resultBuilder .addAccessorAnnotations (code -> code . addLine ("%s" , annotation ));
85
+ resultBuilder .addAccessorAnnotations (Excerpts . add ("%s%n " , annotation ));
84
86
});
85
87
}
86
88
87
- private boolean isXmlAnnotation (AnnotationMirror mirror ) {
88
- Name pkg = elements .getPackageOf (mirror .getAnnotationType ().asElement ()).getQualifiedName ();
89
- return pkg .contentEquals (JACKSON_XML_ANNOTATION_PACKAGE );
89
+ private boolean shouldCopyAnnotation (AnnotationMirror mirror ) {
90
+ TypeElement annotationTypeElement = (TypeElement ) mirror .getAnnotationType ().asElement ();
91
+ Name qualifiedName = annotationTypeElement .getQualifiedName ();
92
+ Name pkg = elements .getPackageOf (annotationTypeElement ).getQualifiedName ();
93
+ return pkg .contentEquals (JACKSON_XML_ANNOTATION_PACKAGE )
94
+ || qualifiedName .contentEquals (JSON_ALIAS );
90
95
}
91
96
92
97
private static GenerateAnnotation generateDefaultAnnotations (ExecutableElement getterMethod ) {
0 commit comments