Skip to content

Commit 7b743fc

Browse files
committed
Merge branch '2.9'
2 parents 9458672 + eb996aa commit 7b743fc

File tree

1 file changed

+39
-30
lines changed

1 file changed

+39
-30
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java

+39-30
Original file line numberDiff line numberDiff line change
@@ -396,22 +396,18 @@ public ValueInstantiator _valueInstantiatorInstance(DeserializationConfig config
396396
config.canOverrideAccessModifiers());
397397
}
398398

399+
/*
400+
/**********************************************************
401+
/* Creator introspection
402+
/**********************************************************
403+
*/
404+
399405
protected void _addDeserializerConstructors(DeserializationContext ctxt,
400406
BeanDescription beanDesc, VisibilityChecker<?> vchecker,
401407
AnnotationIntrospector intr, CreatorCollector creators,
402408
Map<AnnotatedWithParams,BeanPropertyDefinition[]> creatorParams)
403409
throws JsonMappingException
404410
{
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-
415411
// 25-Jan-2017, tatu: As per [databind#1501], [databind#1502], [databind#1503], best
416412
// for now to skip attempts at using anything but no-args constructor (see
417413
// `InnerClassProperty` construction for that)
@@ -421,8 +417,18 @@ protected void _addDeserializerConstructors(DeserializationContext ctxt,
421417
return;
422418
}
423419

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+
}
424429
// 21-Sep-2017, tatu: First let's handle explicitly annotated ones
425430
List<CreatorCandidate> nonAnnotated = new LinkedList<>();
431+
int explCount = 0;
426432
for (AnnotatedConstructor ctor : beanDesc.getConstructors()) {
427433
JsonCreator.Mode creatorMode = intr.findCreatorAnnotation(ctxt.getConfig(), ctor);
428434
if (Mode.DISABLED == creatorMode) {
@@ -449,11 +455,12 @@ protected void _addDeserializerConstructors(DeserializationContext ctxt,
449455
CreatorCandidate.construct(intr, ctor, creatorParams.get(ctor)));
450456
break;
451457
}
458+
++explCount;
452459
}
453-
454460
// 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+
}
457464
List<AnnotatedWithParams> implicitCtors = null;
458465
for (CreatorCandidate candidate : nonAnnotated) {
459466
final int argCount = candidate.paramCount();
@@ -797,6 +804,7 @@ private void _checkImplicitlyNamedConstructors(DeserializationContext ctxt,
797804
throws JsonMappingException
798805
{
799806
List<CreatorCandidate> nonAnnotated = new LinkedList<>();
807+
int explCount = 0;
800808

801809
// 21-Sep-2017, tatu: First let's handle explicitly annotated ones
802810
for (AnnotatedMethod factory : beanDesc.getFactoryMethods()) {
@@ -834,32 +842,33 @@ private void _checkImplicitlyNamedConstructors(DeserializationContext ctxt,
834842
CreatorCandidate.construct(intr, factory, creatorParams.get(factory)));
835843
break;
836844
}
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;
837850
}
838851
// And then implicitly found
839852
for (CreatorCandidate candidate : nonAnnotated) {
840853
final int argCount = candidate.paramCount();
841854
AnnotatedWithParams factory = candidate.creator();
842855
final BeanPropertyDefinition[] propDefs = creatorParams.get(factory);
843856
// 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) {
860858
continue; // 2 and more args? Must be explicit, handled earlier
861859
}
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+
}
863872
AnnotatedParameter nonAnnotatedParam = null;
864873
SettableBeanProperty[] properties = new SettableBeanProperty[argCount];
865874
int implicitNameCount = 0;

0 commit comments

Comments
 (0)