@@ -403,22 +403,23 @@ public ValueInstantiator _valueInstantiatorInstance(DeserializationConfig config
403
403
// in list of constructors, so needs to be handled separately.
404
404
AnnotatedConstructor defaultCtor = beanDesc .findDefaultConstructor ();
405
405
if (defaultCtor != null ) {
406
- if (!creators .hasDefaultCreator () || intr . hasCreatorAnnotation ( defaultCtor )) {
406
+ if (!creators .hasDefaultCreator () || _hasCreatorAnnotation ( ctxt , defaultCtor )) {
407
407
creators .setDefaultCreator (defaultCtor );
408
408
}
409
409
}
410
410
411
411
// may need to keep track for [#725]
412
412
List <AnnotatedConstructor > implicitCtors = null ;
413
413
for (AnnotatedConstructor ctor : beanDesc .getConstructors ()) {
414
- final boolean isCreator = intr .hasCreatorAnnotation (ctor );
414
+ JsonCreator .Mode creatorMode = intr .findCreatorAnnotation (ctxt .getConfig (), ctor );
415
+ final boolean isCreator = (creatorMode != null ) && (creatorMode != JsonCreator .Mode .DISABLED );
415
416
BeanPropertyDefinition [] propDefs = creatorParams .get (ctor );
416
417
final int argCount = ctor .getParameterCount ();
417
418
418
419
// some single-arg factory methods (String, number) are auto-detected
419
420
if (argCount == 1 ) {
420
421
BeanPropertyDefinition argDef = (propDefs == null ) ? null : propDefs [0 ];
421
- boolean useProps = _checkIfCreatorPropertyBased (intr , ctor , argDef );
422
+ boolean useProps = _checkIfCreatorPropertyBased (intr , ctor , argDef , creatorMode );
422
423
423
424
if (useProps ) {
424
425
SettableBeanProperty [] properties = new SettableBeanProperty [1 ];
@@ -583,36 +584,6 @@ protected void _checkImplicitlyNamedConstructors(DeserializationContext ctxt,
583
584
}
584
585
}
585
586
586
- protected boolean _checkIfCreatorPropertyBased (AnnotationIntrospector intr ,
587
- AnnotatedWithParams creator , BeanPropertyDefinition propDef )
588
- {
589
- JsonCreator .Mode mode = intr .findCreatorBinding (creator );
590
-
591
- if (mode == JsonCreator .Mode .PROPERTIES ) {
592
- return true ;
593
- }
594
- if (mode == JsonCreator .Mode .DELEGATING ) {
595
- return false ;
596
- }
597
- // If explicit name, or inject id, property-based
598
- if (((propDef != null ) && propDef .isExplicitlyNamed ())
599
- || (intr .findInjectableValueId (creator .getParameter (0 )) != null )) {
600
- return true ;
601
- }
602
- if (propDef != null ) {
603
- // One more thing: if implicit name matches property with a getter
604
- // or field, we'll consider it property-based as well
605
- String implName = propDef .getName ();
606
- if (implName != null && !implName .isEmpty ()) {
607
- if (propDef .couldSerialize ()) {
608
- return true ;
609
- }
610
- }
611
- }
612
- // in absence of everything else, default to delegating
613
- return false ;
614
- }
615
-
616
587
protected boolean _handleSingleArgumentConstructor (DeserializationContext ctxt ,
617
588
BeanDescription beanDesc , VisibilityChecker <?> vchecker ,
618
589
AnnotationIntrospector intr , CreatorCollector creators ,
@@ -667,7 +638,8 @@ protected boolean _handleSingleArgumentConstructor(DeserializationContext ctxt,
667
638
{
668
639
final DeserializationConfig config = ctxt .getConfig ();
669
640
for (AnnotatedMethod factory : beanDesc .getFactoryMethods ()) {
670
- final boolean isCreator = intr .hasCreatorAnnotation (factory );
641
+ JsonCreator .Mode creatorMode = intr .findCreatorAnnotation (ctxt .getConfig (), factory );
642
+ final boolean isCreator = (creatorMode != null ) && (creatorMode != JsonCreator .Mode .DISABLED );
671
643
final int argCount = factory .getParameterCount ();
672
644
// zero-arg methods must be annotated; if so, are "default creators" [JACKSON-850]
673
645
if (argCount == 0 ) {
@@ -681,7 +653,7 @@ protected boolean _handleSingleArgumentConstructor(DeserializationContext ctxt,
681
653
// some single-arg factory methods (String, number) are auto-detected
682
654
if (argCount == 1 ) {
683
655
BeanPropertyDefinition argDef = (propDefs == null ) ? null : propDefs [0 ];
684
- boolean useProps = _checkIfCreatorPropertyBased (intr , factory , argDef );
656
+ boolean useProps = _checkIfCreatorPropertyBased (intr , factory , argDef , creatorMode );
685
657
if (!useProps ) { // not property based but delegating
686
658
/*boolean added=*/ _handleSingleArgumentFactory (config , beanDesc , vchecker , intr , creators ,
687
659
factory , isCreator );
@@ -891,22 +863,32 @@ protected PropertyName _findImplicitParamName(AnnotatedParameter param, Annotati
891
863
return null ;
892
864
}
893
865
894
- @ Deprecated // in 2.6, remove from 2.7
895
- protected PropertyName _findExplicitParamName (AnnotatedParameter param , AnnotationIntrospector intr )
866
+ protected boolean _checkIfCreatorPropertyBased (AnnotationIntrospector intr ,
867
+ AnnotatedWithParams creator , BeanPropertyDefinition propDef ,
868
+ JsonCreator .Mode creatorMode )
896
869
{
897
- if (param != null && intr != null ) {
898
- return intr . findNameForDeserialization ( param ) ;
870
+ if (creatorMode == JsonCreator . Mode . PROPERTIES ) {
871
+ return true ;
899
872
}
900
- return null ;
901
- }
902
-
903
- @ Deprecated // in 2.6, remove from 2.7
904
- protected boolean _hasExplicitParamName (AnnotatedParameter param , AnnotationIntrospector intr )
905
- {
906
- if (param != null && intr != null ) {
907
- PropertyName n = intr .findNameForDeserialization (param );
908
- return (n != null ) && n .hasSimpleName ();
873
+ if (creatorMode == JsonCreator .Mode .DELEGATING ) {
874
+ return false ;
909
875
}
876
+ // If explicit name, or inject id, property-based
877
+ if (((propDef != null ) && propDef .isExplicitlyNamed ())
878
+ || (intr .findInjectableValueId (creator .getParameter (0 )) != null )) {
879
+ return true ;
880
+ }
881
+ if (propDef != null ) {
882
+ // One more thing: if implicit name matches property with a getter
883
+ // or field, we'll consider it property-based as well
884
+ String implName = propDef .getName ();
885
+ if (implName != null && !implName .isEmpty ()) {
886
+ if (propDef .couldSerialize ()) {
887
+ return true ;
888
+ }
889
+ }
890
+ }
891
+ // in absence of everything else, default to delegating
910
892
return false ;
911
893
}
912
894
@@ -1240,7 +1222,7 @@ public JsonDeserializer<?> createEnumDeserializer(DeserializationContext ctxt,
1240
1222
: valueInstantiator .getFromObjectArguments (ctxt .getConfig ());
1241
1223
// May have @JsonCreator for static factory method:
1242
1224
for (AnnotatedMethod factory : beanDesc .getFactoryMethods ()) {
1243
- if (ctxt . getAnnotationIntrospector (). hasCreatorAnnotation ( factory )) {
1225
+ if (_hasCreatorAnnotation ( ctxt , factory )) {
1244
1226
int argCount = factory .getParameterCount ();
1245
1227
if (argCount == 1 ) {
1246
1228
Class <?> returnType = factory .getRawReturnType ();
@@ -1441,9 +1423,8 @@ private KeyDeserializer _createEnumKeyDeserializer(DeserializationContext ctxt,
1441
1423
}
1442
1424
EnumResolver enumRes = constructEnumResolver (enumClass , config , beanDesc .findJsonValueMethod ());
1443
1425
// May have @JsonCreator for static factory method:
1444
- final AnnotationIntrospector ai = config .getAnnotationIntrospector ();
1445
1426
for (AnnotatedMethod factory : beanDesc .getFactoryMethods ()) {
1446
- if (ai . hasCreatorAnnotation ( factory )) {
1427
+ if (_hasCreatorAnnotation ( ctxt , factory )) {
1447
1428
int argCount = factory .getParameterCount ();
1448
1429
if (argCount == 1 ) {
1449
1430
Class <?> returnType = factory .getRawReturnType ();
@@ -1874,6 +1855,19 @@ protected EnumResolver constructEnumResolver(Class<?> enumClass,
1874
1855
return EnumResolver .constructUnsafe (enumClass , config .getAnnotationIntrospector ());
1875
1856
}
1876
1857
1858
+ /**
1859
+ * @since 2.9
1860
+ */
1861
+ protected boolean _hasCreatorAnnotation (DeserializationContext ctxt ,
1862
+ Annotated ann ) {
1863
+ AnnotationIntrospector intr = ctxt .getAnnotationIntrospector ();
1864
+ if (intr != null ) {
1865
+ JsonCreator .Mode mode = intr .findCreatorAnnotation (ctxt .getConfig (), ann );
1866
+ return (mode != null ) && (mode != JsonCreator .Mode .DISABLED );
1867
+ }
1868
+ return false ;
1869
+ }
1870
+
1877
1871
/*
1878
1872
/**********************************************************
1879
1873
/* Deprecated helper methods
0 commit comments