@@ -396,22 +396,18 @@ public ValueInstantiator _valueInstantiatorInstance(DeserializationConfig config
396
396
config .canOverrideAccessModifiers ());
397
397
}
398
398
399
+ /*
400
+ /**********************************************************
401
+ /* Creator introspection
402
+ /**********************************************************
403
+ */
404
+
399
405
protected void _addDeserializerConstructors (DeserializationContext ctxt ,
400
406
BeanDescription beanDesc , VisibilityChecker <?> vchecker ,
401
407
AnnotationIntrospector intr , CreatorCollector creators ,
402
408
Map <AnnotatedWithParams ,BeanPropertyDefinition []> creatorParams )
403
409
throws JsonMappingException
404
410
{
405
- // First things first: the "default constructor" (zero-arg
406
- // constructor; whether implicit or explicit) is NOT included
407
- // in list of constructors, so needs to be handled separately.
408
- AnnotatedConstructor defaultCtor = beanDesc .findDefaultConstructor ();
409
- if (defaultCtor != null ) {
410
- if (!creators .hasDefaultCreator () || _hasCreatorAnnotation (ctxt , defaultCtor )) {
411
- creators .setDefaultCreator (defaultCtor );
412
- }
413
- }
414
-
415
411
// 25-Jan-2017, tatu: As per [databind#1501], [databind#1502], [databind#1503], best
416
412
// for now to skip attempts at using anything but no-args constructor (see
417
413
// `InnerClassProperty` construction for that)
@@ -421,8 +417,18 @@ protected void _addDeserializerConstructors(DeserializationContext ctxt,
421
417
return ;
422
418
}
423
419
420
+ // First things first: the "default constructor" (zero-arg
421
+ // constructor; whether implicit or explicit) is NOT included
422
+ // in list of constructors, so needs to be handled separately.
423
+ AnnotatedConstructor defaultCtor = beanDesc .findDefaultConstructor ();
424
+ if (defaultCtor != null ) {
425
+ if (!creators .hasDefaultCreator () || _hasCreatorAnnotation (ctxt , defaultCtor )) {
426
+ creators .setDefaultCreator (defaultCtor );
427
+ }
428
+ }
424
429
// 21-Sep-2017, tatu: First let's handle explicitly annotated ones
425
430
List <CreatorCandidate > nonAnnotated = new LinkedList <>();
431
+ int explCount = 0 ;
426
432
for (AnnotatedConstructor ctor : beanDesc .getConstructors ()) {
427
433
JsonCreator .Mode creatorMode = intr .findCreatorAnnotation (ctxt .getConfig (), ctor );
428
434
if (Mode .DISABLED == creatorMode ) {
@@ -449,11 +455,12 @@ protected void _addDeserializerConstructors(DeserializationContext ctxt,
449
455
CreatorCandidate .construct (intr , ctor , creatorParams .get (ctor )));
450
456
break ;
451
457
}
458
+ ++explCount ;
452
459
}
453
-
454
460
// And only if and when those handled, consider potentially visible ones
455
-
456
- // may need to keep track for [#725]
461
+ if (explCount > 0 ) { // TODO: split method into two since we could have expl factories
462
+ return ;
463
+ }
457
464
List <AnnotatedWithParams > implicitCtors = null ;
458
465
for (CreatorCandidate candidate : nonAnnotated ) {
459
466
final int argCount = candidate .paramCount ();
@@ -797,6 +804,7 @@ private void _checkImplicitlyNamedConstructors(DeserializationContext ctxt,
797
804
throws JsonMappingException
798
805
{
799
806
List <CreatorCandidate > nonAnnotated = new LinkedList <>();
807
+ int explCount = 0 ;
800
808
801
809
// 21-Sep-2017, tatu: First let's handle explicitly annotated ones
802
810
for (AnnotatedMethod factory : beanDesc .getFactoryMethods ()) {
@@ -834,32 +842,33 @@ private void _checkImplicitlyNamedConstructors(DeserializationContext ctxt,
834
842
CreatorCandidate .construct (intr , factory , creatorParams .get (factory )));
835
843
break ;
836
844
}
845
+ ++explCount ;
846
+ }
847
+ // And only if and when those handled, consider potentially visible ones
848
+ if (explCount > 0 ) { // TODO: split method into two since we could have expl factories
849
+ return ;
837
850
}
838
851
// And then implicitly found
839
852
for (CreatorCandidate candidate : nonAnnotated ) {
840
853
final int argCount = candidate .paramCount ();
841
854
AnnotatedWithParams factory = candidate .creator ();
842
855
final BeanPropertyDefinition [] propDefs = creatorParams .get (factory );
843
856
// some single-arg factory methods (String, number) are auto-detected
844
- if (argCount == 1 ) {
845
- // more than 2 args, must have @JsonCreator (and 0-args handled earlier
846
- BeanPropertyDefinition argDef = candidate .propertyDef (0 );
847
- boolean useProps = _checkIfCreatorPropertyBased (intr , factory , argDef );
848
- if (!useProps ) { // not property based but delegating
849
- /*boolean added=*/ _handleSingleArgumentCreator (creators ,
850
- factory , false , vchecker .isCreatorVisible (factory ));
851
- // 23-Sep-2016, tatu: [databind#1383]: Need to also sever link to avoid possible
852
- // later problems with "unresolved" constructor property
853
- if (argDef != null ) {
854
- ((POJOPropertyBuilder ) argDef ).removeConstructors ();
855
- }
856
- continue ;
857
- }
858
- // fall through if there's name
859
- } else {
857
+ if (argCount != 1 ) {
860
858
continue ; // 2 and more args? Must be explicit, handled earlier
861
859
}
862
- // 1 or more args; all params must have name annotations
860
+ BeanPropertyDefinition argDef = candidate .propertyDef (0 );
861
+ boolean useProps = _checkIfCreatorPropertyBased (intr , factory , argDef );
862
+ if (!useProps ) { // not property based but delegating
863
+ /*boolean added=*/ _handleSingleArgumentCreator (creators ,
864
+ factory , false , vchecker .isCreatorVisible (factory ));
865
+ // 23-Sep-2016, tatu: [databind#1383]: Need to also sever link to avoid possible
866
+ // later problems with "unresolved" constructor property
867
+ if (argDef != null ) {
868
+ ((POJOPropertyBuilder ) argDef ).removeConstructors ();
869
+ }
870
+ continue ;
871
+ }
863
872
AnnotatedParameter nonAnnotatedParam = null ;
864
873
SettableBeanProperty [] properties = new SettableBeanProperty [argCount ];
865
874
int implicitNameCount = 0 ;
0 commit comments