@@ -252,41 +252,54 @@ protected ValueInstantiator _constructDefaultValueInstantiator(DeserializationCo
252
252
BeanDescription beanDesc )
253
253
throws JsonMappingException
254
254
{
255
- CreatorCollector creators = new CreatorCollector (beanDesc , ctxt .getConfig ());
256
- AnnotationIntrospector intr = ctxt .getAnnotationIntrospector ();
257
-
258
- // need to construct suitable visibility checker:
259
- final DeserializationConfig config = ctxt .getConfig ();
260
- VisibilityChecker <?> vchecker = config .getDefaultVisibilityChecker (beanDesc .getBeanClass (),
261
- beanDesc .getClassInfo ());
255
+ final CreatorCollectionState ccState ;
256
+
257
+ {
258
+ final DeserializationConfig config = ctxt .getConfig ();
259
+ // need to construct suitable visibility checker:
260
+ final VisibilityChecker <?> vchecker = config .getDefaultVisibilityChecker (beanDesc .getBeanClass (),
261
+ beanDesc .getClassInfo ());
262
+
263
+ // 24-Sep-2014, tatu: Tricky part first; need to merge resolved property information
264
+ // (which has creator parameters sprinkled around) with actual creator
265
+ // declarations (which are needed to access creator annotation, amongst other things).
266
+ // Easiest to combine that info first, then pass it to remaining processing.
267
+
268
+ // 15-Mar-2015, tatu: Alas, this won't help with constructors that only have implicit
269
+ // names. Those will need to be resolved later on.
270
+ final CreatorCollector creators = new CreatorCollector (beanDesc , config );
271
+ Map <AnnotatedWithParams ,BeanPropertyDefinition []> creatorDefs = _findCreatorsFromProperties (ctxt ,
272
+ beanDesc );
273
+ ccState = new CreatorCollectionState (ctxt , beanDesc , vchecker ,
274
+ creators , creatorDefs );
275
+ }
262
276
263
- /* 24-Sep-2014, tatu: Tricky part first; need to merge resolved property information
264
- * (which has creator parameters sprinkled around) with actual creator
265
- * declarations (which are needed to access creator annotation, amongst other things).
266
- * Easiest to combine that info first, then pass it to remaining processing.
267
- */
268
- /* 15-Mar-2015, tatu: Alas, this won't help with constructors that only have implicit
269
- * names. Those will need to be resolved later on.
270
- */
271
- Map <AnnotatedWithParams ,BeanPropertyDefinition []> creatorDefs = _findCreatorsFromProperties (ctxt ,
272
- beanDesc );
273
277
// Important: first add factory methods; then constructors, so
274
278
// latter can override former!
275
- _addDeserializerFactoryMethods (ctxt , beanDesc , vchecker , intr , creators , creatorDefs );
279
+ _addDeserializerFactoryMethods (ctxt , ccState );
276
280
// constructors only usable on concrete types:
277
281
if (beanDesc .getType ().isConcrete ()) {
278
282
// [databind#2709]: Record support
279
283
if (beanDesc .getType ().isRecordType ()) {
280
284
final List <String > names = new ArrayList <>();
281
285
AnnotatedConstructor canonical = JDK14Util .findRecordConstructor (ctxt , beanDesc , names );
282
286
if (canonical != null ) {
283
- _addRecordConstructor (ctxt , beanDesc , creators , canonical , names );
284
- return creators .constructValueInstantiator (ctxt );
287
+ _addRecordConstructor (ctxt , ccState , canonical , names );
288
+ return ccState . creators .constructValueInstantiator (ctxt );
285
289
}
286
290
}
287
- _addDeserializerConstructors (ctxt , beanDesc , vchecker , intr , creators , creatorDefs );
291
+ // 25-Jan-2017, tatu: As per [databind#1501], [databind#1502], [databind#1503], best
292
+ // for now to skip attempts at using anything but no-args constructor (see
293
+ // `InnerClassProperty` construction for that)
294
+ final boolean isNonStaticInnerClass = beanDesc .isNonStaticInnerClass ();
295
+ if (isNonStaticInnerClass ) {
296
+ // TODO: look for `@JsonCreator` annotated ones, throw explicit exception?
297
+ ;
298
+ } else {
299
+ _addDeserializerConstructors (ctxt , ccState );
300
+ }
288
301
}
289
- return creators .constructValueInstantiator (ctxt );
302
+ return ccState . creators .constructValueInstantiator (ctxt );
290
303
}
291
304
292
305
protected Map <AnnotatedWithParams ,BeanPropertyDefinition []> _findCreatorsFromProperties (DeserializationContext ctxt ,
@@ -364,20 +377,15 @@ public ValueInstantiator _valueInstantiatorInstance(DeserializationConfig config
364
377
*/
365
378
366
379
protected void _addDeserializerConstructors (DeserializationContext ctxt ,
367
- BeanDescription beanDesc , VisibilityChecker <?> vchecker ,
368
- AnnotationIntrospector intr , CreatorCollector creators ,
369
- Map <AnnotatedWithParams ,BeanPropertyDefinition []> creatorParams )
380
+ CreatorCollectionState ccState )
370
381
throws JsonMappingException
371
382
{
372
- // 25-Jan-2017, tatu: As per [databind#1501], [databind#1502], [databind#1503], best
373
- // for now to skip attempts at using anything but no-args constructor (see
374
- // `InnerClassProperty` construction for that)
375
- final boolean isNonStaticInnerClass = beanDesc .isNonStaticInnerClass ();
376
- if (isNonStaticInnerClass ) {
377
- // TODO: look for `@JsonCreator` annotated ones, throw explicit exception?
378
- return ;
379
- }
380
-
383
+ final BeanDescription beanDesc = ccState .beanDesc ;
384
+ final CreatorCollector creators = ccState .creators ;
385
+ final AnnotationIntrospector intr = ccState .annotationIntrospector ();
386
+ final VisibilityChecker <?> vchecker = ccState .vchecker ;
387
+ final Map <AnnotatedWithParams , BeanPropertyDefinition []> creatorParams = ccState .creatorDefs ;
388
+
381
389
// First things first: the "default constructor" (zero-arg
382
390
// constructor; whether implicit or explicit) is NOT included
383
391
// in list of constructors, so needs to be handled separately.
@@ -556,8 +564,7 @@ protected void _addDeserializerConstructors(DeserializationContext ctxt,
556
564
*
557
565
* @since 2.12
558
566
*/
559
- protected void _addRecordConstructor (DeserializationContext ctxt ,
560
- BeanDescription beanDesc , CreatorCollector creators ,
567
+ protected void _addRecordConstructor (DeserializationContext ctxt , CreatorCollectionState ccState ,
561
568
AnnotatedConstructor canonical , List <String > implicitNames )
562
569
throws JsonMappingException
563
570
{
@@ -572,9 +579,9 @@ protected void _addRecordConstructor(DeserializationContext ctxt,
572
579
if (name == null || name .isEmpty ()) {
573
580
name = PropertyName .construct (implicitNames .get (i ));
574
581
}
575
- properties [i ] = constructCreatorProperty (ctxt , beanDesc , name , i , param , injectable );
582
+ properties [i ] = constructCreatorProperty (ctxt , ccState . beanDesc , name , i , param , injectable );
576
583
}
577
- creators .addPropertyCreator (canonical , false , properties );
584
+ ccState . creators .addPropertyCreator (canonical , false , properties );
578
585
}
579
586
580
587
/**
@@ -852,11 +859,15 @@ private void _checkImplicitlyNamedConstructors(DeserializationContext ctxt,
852
859
}
853
860
854
861
protected void _addDeserializerFactoryMethods
855
- (DeserializationContext ctxt , BeanDescription beanDesc , VisibilityChecker <?> vchecker ,
856
- AnnotationIntrospector intr , CreatorCollector creators ,
857
- Map <AnnotatedWithParams ,BeanPropertyDefinition []> creatorParams )
862
+ (DeserializationContext ctxt , CreatorCollectionState ccState )
858
863
throws JsonMappingException
859
864
{
865
+ final BeanDescription beanDesc = ccState .beanDesc ;
866
+ final CreatorCollector creators = ccState .creators ;
867
+ final AnnotationIntrospector intr = ccState .annotationIntrospector ();
868
+ final VisibilityChecker <?> vchecker = ccState .vchecker ;
869
+ final Map <AnnotatedWithParams , BeanPropertyDefinition []> creatorParams = ccState .creatorDefs ;
870
+
860
871
List <CreatorCandidate > nonAnnotated = new LinkedList <>();
861
872
int explCount = 0 ;
862
873
@@ -2437,4 +2448,34 @@ public static Class<?> findMapFallback(JavaType type) {
2437
2448
return _mapFallbacks .get (type .getRawClass ().getName ());
2438
2449
}
2439
2450
}
2451
+
2452
+ /**
2453
+ * Helper class to contain largish number of parameters that need to be passed
2454
+ * during Creator introspection.
2455
+ *
2456
+ * @since 2.12
2457
+ */
2458
+ protected static class CreatorCollectionState {
2459
+ public final DeserializationContext context ;
2460
+ public final BeanDescription beanDesc ;
2461
+ public final VisibilityChecker <?> vchecker ;
2462
+ public final CreatorCollector creators ;
2463
+ public final Map <AnnotatedWithParams ,BeanPropertyDefinition []> creatorDefs ;
2464
+
2465
+ public CreatorCollectionState (DeserializationContext ctxt , BeanDescription bd ,
2466
+ VisibilityChecker <?> vc ,
2467
+ CreatorCollector cc ,
2468
+ Map <AnnotatedWithParams ,BeanPropertyDefinition []> cdefs )
2469
+ {
2470
+ context = ctxt ;
2471
+ beanDesc = bd ;
2472
+ vchecker = vc ;
2473
+ creators = cc ;
2474
+ creatorDefs = cdefs ;
2475
+ }
2476
+
2477
+ public AnnotationIntrospector annotationIntrospector () {
2478
+ return context .getAnnotationIntrospector ();
2479
+ }
2480
+ }
2440
2481
}
0 commit comments