12
12
import com .fasterxml .jackson .databind .AnnotationIntrospector ;
13
13
import com .fasterxml .jackson .databind .JavaType ;
14
14
import com .fasterxml .jackson .databind .introspect .AnnotatedClass .Creators ;
15
+ import com .fasterxml .jackson .databind .type .TypeFactory ;
15
16
import com .fasterxml .jackson .databind .util .ClassUtil ;
16
17
17
18
/**
@@ -27,6 +28,9 @@ final class AnnotatedCreatorCollector
27
28
28
29
private final TypeResolutionContext _typeContext ;
29
30
31
+ // @since 2.11.3
32
+ private final TypeFactory _typeFactory ;
33
+
30
34
/**
31
35
* @since 2.11
32
36
*/
@@ -36,23 +40,36 @@ final class AnnotatedCreatorCollector
36
40
37
41
private AnnotatedConstructor _defaultConstructor ;
38
42
39
- AnnotatedCreatorCollector (AnnotationIntrospector intr ,
43
+ AnnotatedCreatorCollector (AnnotationIntrospector intr , TypeFactory tf ,
40
44
TypeResolutionContext tc , boolean collectAnnotations )
41
45
{
42
46
super (intr );
47
+ _typeFactory = tf ;
43
48
_typeContext = tc ;
44
49
_collectAnnotations = collectAnnotations ;
45
50
}
46
51
52
+ @ Deprecated // since 2.11.3; to be removed ASAP (2.12.0)
47
53
public static Creators collectCreators (AnnotationIntrospector intr ,
48
- TypeResolutionContext tc ,
54
+ TypeResolutionContext tc ,
55
+ JavaType type , Class <?> primaryMixIn , boolean collectAnnotations )
56
+ {
57
+ return collectCreators (intr , TypeFactory .defaultInstance (),
58
+ tc , type , primaryMixIn , collectAnnotations );
59
+ }
60
+
61
+ /**
62
+ * @since 2.11.3
63
+ */
64
+ public static Creators collectCreators (AnnotationIntrospector intr ,
65
+ TypeFactory typeFactory , TypeResolutionContext tc ,
49
66
JavaType type , Class <?> primaryMixIn , boolean collectAnnotations )
50
67
{
51
68
final boolean checkClassAnnotations = (intr != null )
52
69
&& !ClassUtil .isJDKClass (type .getRawClass ());
53
70
54
71
// Constructor also always members of resolved class, parent == resolution context
55
- return new AnnotatedCreatorCollector (intr , tc , checkClassAnnotations )
72
+ return new AnnotatedCreatorCollector (intr , typeFactory , tc , checkClassAnnotations )
56
73
.collect (type , primaryMixIn );
57
74
}
58
75
@@ -203,6 +220,13 @@ private List<AnnotatedMethod> _findPotentialFactories(JavaType type, Class<?> pr
203
220
if (candidates == null ) {
204
221
return Collections .emptyList ();
205
222
}
223
+ // 05-Sep-2020, tatu: Important fix wrt [databind#2821] -- static methods
224
+ // do NOT have type binding context of the surrounding class and although
225
+ // passing that should not break things, it appears to... Regardless,
226
+ // it should not be needed or useful as those bindings are only available
227
+ // to non-static members
228
+ TypeResolutionContext typeResCtxt = new TypeResolutionContext .Empty (_typeFactory );
229
+
206
230
int factoryCount = candidates .size ();
207
231
List <AnnotatedMethod > result = new ArrayList <>(factoryCount );
208
232
for (int i = 0 ; i < factoryCount ; ++i ) {
@@ -225,7 +249,8 @@ private List<AnnotatedMethod> _findPotentialFactories(JavaType type, Class<?> pr
225
249
for (int i = 0 ; i < factoryCount ; ++i ) {
226
250
if (key .equals (methodKeys [i ])) {
227
251
result .set (i ,
228
- constructFactoryCreator (candidates .get (i ), mixinFactory ));
252
+ constructFactoryCreator (candidates .get (i ),
253
+ typeResCtxt , mixinFactory ));
229
254
break ;
230
255
}
231
256
}
@@ -236,7 +261,8 @@ private List<AnnotatedMethod> _findPotentialFactories(JavaType type, Class<?> pr
236
261
AnnotatedMethod factory = result .get (i );
237
262
if (factory == null ) {
238
263
result .set (i ,
239
- constructFactoryCreator (candidates .get (i ), null ));
264
+ constructFactoryCreator (candidates .get (i ),
265
+ typeResCtxt , null ));
240
266
}
241
267
}
242
268
return result ;
@@ -308,18 +334,19 @@ protected AnnotatedConstructor constructNonDefaultConstructor(ClassUtil.Ctor cto
308
334
collectAnnotations (ctor , mixin ), resolvedAnnotations );
309
335
}
310
336
311
- protected AnnotatedMethod constructFactoryCreator (Method m , Method mixin )
337
+ protected AnnotatedMethod constructFactoryCreator (Method m ,
338
+ TypeResolutionContext typeResCtxt , Method mixin )
312
339
{
313
340
final int paramCount = m .getParameterTypes ().length ;
314
341
if (_intr == null ) { // when annotation processing is disabled
315
- return new AnnotatedMethod (_typeContext , m , _emptyAnnotationMap (),
342
+ return new AnnotatedMethod (typeResCtxt , m , _emptyAnnotationMap (),
316
343
_emptyAnnotationMaps (paramCount ));
317
344
}
318
345
if (paramCount == 0 ) { // common enough we can slightly optimize
319
- return new AnnotatedMethod (_typeContext , m , collectAnnotations (m , mixin ),
346
+ return new AnnotatedMethod (typeResCtxt , m , collectAnnotations (m , mixin ),
320
347
NO_ANNOTATION_MAPS );
321
348
}
322
- return new AnnotatedMethod (_typeContext , m , collectAnnotations (m , mixin ),
349
+ return new AnnotatedMethod (typeResCtxt , m , collectAnnotations (m , mixin ),
323
350
collectAnnotations (m .getParameterAnnotations (),
324
351
(mixin == null ) ? null : mixin .getParameterAnnotations ()));
325
352
}
0 commit comments