@@ -33,6 +33,11 @@ public class AnnotatedClassResolver
33
33
private final Class <?> _class ;
34
34
private final Class <?> _primaryMixin ;
35
35
36
+ /**
37
+ * @since 2.11
38
+ */
39
+ private final boolean _collectAnnotations ;
40
+
36
41
AnnotatedClassResolver (MapperConfig <?> config , JavaType type , MixInResolver r ) {
37
42
_config = config ;
38
43
_type = type ;
@@ -41,7 +46,10 @@ public class AnnotatedClassResolver
41
46
_bindings = type .getBindings ();
42
47
_intr = config .isAnnotationProcessingEnabled ()
43
48
? config .getAnnotationIntrospector () : null ;
44
- _primaryMixin = _config .findMixInClassFor (_class );
49
+ _primaryMixin = (r == null ) ? null : r .findMixInClassFor (_class );
50
+
51
+ // Also... JDK types do not have annotations that are of interest to us
52
+ _collectAnnotations = (_intr != null ) && !ClassUtil .isJDKClass (_class );
45
53
}
46
54
47
55
AnnotatedClassResolver (MapperConfig <?> config , Class <?> cls , MixInResolver r ) {
@@ -56,8 +64,10 @@ public class AnnotatedClassResolver
56
64
} else {
57
65
_intr = config .isAnnotationProcessingEnabled ()
58
66
? config .getAnnotationIntrospector () : null ;
59
- _primaryMixin = _config .findMixInClassFor (_class );
67
+ _primaryMixin = ( r == null ) ? null : r .findMixInClassFor (_class );
60
68
}
69
+
70
+ _collectAnnotations = (_intr != null ) && !ClassUtil .isJDKClass (_class );
61
71
}
62
72
63
73
public static AnnotatedClass resolve (MapperConfig <?> config , JavaType forType ,
@@ -116,15 +126,17 @@ AnnotatedClass resolveFully() {
116
126
List <JavaType > superTypes = ClassUtil .findSuperTypes (_type , null , false );
117
127
return new AnnotatedClass (_type , _class , superTypes , _primaryMixin ,
118
128
resolveClassAnnotations (superTypes ),
119
- _bindings , _intr , _mixInResolver , _config .getTypeFactory ());
129
+ _bindings , _intr , _mixInResolver , _config .getTypeFactory (),
130
+ _collectAnnotations );
120
131
121
132
}
122
133
123
134
AnnotatedClass resolveWithoutSuperTypes () {
124
135
List <JavaType > superTypes = Collections .<JavaType >emptyList ();
125
136
return new AnnotatedClass (null , _class , superTypes , _primaryMixin ,
126
137
resolveClassAnnotations (superTypes ),
127
- _bindings , _intr , _config , _config .getTypeFactory ());
138
+ _bindings , _intr , _mixInResolver , _config .getTypeFactory (),
139
+ _collectAnnotations );
128
140
}
129
141
130
142
/*
@@ -144,33 +156,48 @@ private Annotations resolveClassAnnotations(List<JavaType> superTypes)
144
156
if (_intr == null ) {
145
157
return NO_ANNOTATIONS ;
146
158
}
159
+ // Plus we may or may not have mix-ins to consider
160
+ final boolean checkMixIns = (_mixInResolver != null )
161
+ && (!(_mixInResolver instanceof SimpleMixInResolver )
162
+ || ((SimpleMixInResolver ) _mixInResolver ).hasMixIns ());
163
+
164
+ // also skip if there's nothing to do
165
+ if (!checkMixIns && !_collectAnnotations ) {
166
+ return NO_ANNOTATIONS ;
167
+ }
168
+
147
169
AnnotationCollector resolvedCA = AnnotationCollector .emptyCollector ();
148
170
// add mix-in annotations first (overrides)
149
171
if (_primaryMixin != null ) {
150
172
resolvedCA = _addClassMixIns (resolvedCA , _class , _primaryMixin );
151
173
}
152
174
// then annotations from the class itself:
153
- resolvedCA = _addAnnotationsIfNotPresent (resolvedCA ,
154
- ClassUtil .findClassAnnotations (_class ));
175
+ // 06-Oct-2019, tatu: [databind#2464] Skip class annotations for JDK classes
176
+ if (_collectAnnotations ) {
177
+ resolvedCA = _addAnnotationsIfNotPresent (resolvedCA ,
178
+ ClassUtil .findClassAnnotations (_class ));
179
+ }
155
180
156
181
// and then from super types
157
182
for (JavaType type : superTypes ) {
158
183
// and mix mix-in annotations in-between
159
- if (_mixInResolver != null ) {
184
+ if (checkMixIns ) {
160
185
Class <?> cls = type .getRawClass ();
161
186
resolvedCA = _addClassMixIns (resolvedCA , cls ,
162
187
_mixInResolver .findMixInClassFor (cls ));
163
188
}
164
- resolvedCA = _addAnnotationsIfNotPresent (resolvedCA ,
165
- ClassUtil .findClassAnnotations (type .getRawClass ()));
189
+ if (_collectAnnotations ) {
190
+ resolvedCA = _addAnnotationsIfNotPresent (resolvedCA ,
191
+ ClassUtil .findClassAnnotations (type .getRawClass ()));
192
+ }
166
193
}
167
- /* and finally... any annotations there might be for plain
168
- * old Object.class: separate because for all other purposes
169
- * it is just ignored (not included in super types)
170
- */
194
+
195
+ // and finally... any annotations there might be for plain old Object.class:
196
+ // separate because otherwise it is just ignored (not included in super types)
197
+
171
198
// 12-Jul-2009, tatu: Should this be done for interfaces too?
172
199
// For now, yes, seems useful for some cases, and not harmful for any?
173
- if (_mixInResolver != null ) {
200
+ if (checkMixIns ) {
174
201
resolvedCA = _addClassMixIns (resolvedCA , Object .class ,
175
202
_mixInResolver .findMixInClassFor (Object .class ));
176
203
}
0 commit comments