|
8 | 8 | import java.util.concurrent.atomic.AtomicReference;
|
9 | 9 |
|
10 | 10 | import com.fasterxml.jackson.annotation.*;
|
| 11 | +import com.fasterxml.jackson.annotation.JacksonInject.Value; |
11 | 12 | import com.fasterxml.jackson.annotation.JsonCreator.Mode;
|
12 | 13 |
|
13 | 14 | import com.fasterxml.jackson.core.JsonParser;
|
@@ -475,26 +476,37 @@ protected void _addImplicitConstructorCreators(DeserializationContext ctxt,
|
475 | 476 | CreatorCollectionState ccState, List<CreatorCandidate> ctorCandidates)
|
476 | 477 | throws JsonMappingException
|
477 | 478 | {
|
| 479 | + final DeserializationConfig config = ctxt.getConfig(); |
478 | 480 | final BeanDescription beanDesc = ccState.beanDesc;
|
479 | 481 | final CreatorCollector creators = ccState.creators;
|
480 | 482 | final AnnotationIntrospector intr = ccState.annotationIntrospector();
|
481 | 483 | final VisibilityChecker<?> vchecker = ccState.vchecker;
|
482 | 484 | List<AnnotatedWithParams> implicitCtors = null;
|
| 485 | + final boolean preferPropsBased = config.getConstructorDetector().singleArgCreatorDefaultsToProperties(); |
483 | 486 |
|
484 | 487 | for (CreatorCandidate candidate : ctorCandidates) {
|
485 | 488 | final int argCount = candidate.paramCount();
|
486 | 489 | final AnnotatedWithParams ctor = candidate.creator();
|
487 |
| - |
488 | 490 | // some single-arg factory methods (String, number) are auto-detected
|
489 | 491 | if (argCount == 1) {
|
490 |
| - BeanPropertyDefinition propDef = candidate.propertyDef(0); |
491 |
| - boolean useProps = _checkIfCreatorPropertyBased(intr, ctor, propDef); |
| 492 | + final BeanPropertyDefinition propDef = candidate.propertyDef(0); |
| 493 | + final boolean useProps = preferPropsBased || _checkIfCreatorPropertyBased(intr, ctor, propDef); |
492 | 494 |
|
493 | 495 | if (useProps) {
|
494 | 496 | SettableBeanProperty[] properties = new SettableBeanProperty[1];
|
| 497 | + final JacksonInject.Value injection = candidate.injection(0); |
| 498 | + |
| 499 | + // 18-Sep-2020, tatu: [databind#1498] looks like implicit name not linked |
| 500 | + // unless annotation found, so try again from here |
495 | 501 | PropertyName name = candidate.paramName(0);
|
| 502 | + if (name == null) { |
| 503 | + name = candidate.findImplicitParamName(0); |
| 504 | + if ((name == null) && (injection == null)) { |
| 505 | + continue; |
| 506 | + } |
| 507 | + } |
496 | 508 | properties[0] = constructCreatorProperty(ctxt, beanDesc, name, 0,
|
497 |
| - candidate.parameter(0), candidate.injection(0)); |
| 509 | + candidate.parameter(0), injection); |
498 | 510 | creators.addPropertyCreator(ctor, false, properties);
|
499 | 511 | } else {
|
500 | 512 | /*boolean added = */ _handleSingleArgumentCreator(creators,
|
|
0 commit comments