@@ -1044,49 +1044,11 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p, Deseri
10441044 }
10451045
10461046 // Last creator property to set?
1047- if (buffer .assignParameter (creatorProp ,
1048- _deserializeWithErrorWrapping (p , ctxt , creatorProp ))) {
1049- t = p .nextToken (); // to move to following PROPERTY_NAME/END_OBJECT
1050- Object bean ;
1051- try {
1052- bean = creator .build (ctxt , buffer );
1053- } catch (Exception e ) {
1054- bean = wrapInstantiationProblem (ctxt , e );
1055- }
1056- // [databind#631]: Assign current value, to be accessible by custom serializers
1057- p .assignCurrentValue (bean );
1058- // [databind#4938] Since 2.19, allow returning `null` from creator,
1059- // but if so, need to skip all possibly relevant content
1060- if (bean == null ) {
1061- // 13-Mar-2025, tatu: We don't have "referrings" here for some reason...
1062- // Nor "unknown" since unwrapping makes it impossible to tell unwrapped
1063- // and unknown apart
1064- _handleNullFromPropsBasedCreator (p , ctxt , null , null );
1065- return null ;
1066- }
1047+ // [databind#4690] cannot quit early as optimization any more
1048+ // if (buffer.assignParameter(creatorProp, value)) { ... build ... }
1049+ buffer .assignParameter (creatorProp ,
1050+ _deserializeWithErrorWrapping (p , ctxt , creatorProp ));
10671051
1068- // if so, need to copy all remaining tokens into buffer
1069- while (t == JsonToken .PROPERTY_NAME ) {
1070- // NOTE: do NOT skip name as it needs to be copied; `copyCurrentStructure` does that
1071- tokens .copyCurrentStructure (p );
1072- t = p .nextToken ();
1073- }
1074- // 28-Aug-2018, tatu: Let's add sanity check here, easier to catch off-by-some
1075- // problems if we maintain invariants
1076- if (t != JsonToken .END_OBJECT ) {
1077- ctxt .reportWrongTokenException (this , JsonToken .END_OBJECT ,
1078- "Attempted to unwrap '%s' value" ,
1079- handledType ().getName ());
1080- }
1081- tokens .writeEndObject ();
1082- if (bean .getClass () != _beanType .getRawClass ()) {
1083- // !!! 08-Jul-2011, tatu: Could probably support; but for now
1084- // it's too complicated, so bail out
1085- return ctxt .reportInputMismatch (creatorProp ,
1086- "Cannot create polymorphic instances with unwrapped values" );
1087- }
1088- return _unwrappedPropertyHandler .processUnwrapped (p , ctxt , bean , tokens );
1089- }
10901052 continue ;
10911053 }
10921054 // regular property? needs buffering
@@ -1118,6 +1080,8 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p, Deseri
11181080 }
11191081 }
11201082
1083+ tokens .writeEndObject ();
1084+
11211085 // We could still have some not-yet-set creator properties that are unwrapped.
11221086 // These have to be processed last, because 'tokens' contains all properties
11231087 // that remain after regular deserialization.
@@ -1130,14 +1094,19 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p, Deseri
11301094 } catch (Exception e ) {
11311095 return wrapInstantiationProblem (ctxt , e );
11321096 }
1097+ p .assignCurrentValue (bean );
1098+
11331099 // [databind#4938] Since 2.19, allow returning `null` from creator,
11341100 // but if so, need to skip all possibly relevant content
11351101 if (bean == null ) {
11361102 // no "referrings" here either:
1137- _handleNullFromPropsBasedCreator (null , ctxt , null , null );
1103+ _handleNullFromPropsBasedCreator (p , ctxt , null , null );
11381104 return null ;
11391105 }
1140-
1106+ if (bean .getClass () != _beanType .getRawClass ()) {
1107+ return ctxt .reportInputMismatch (_beanType ,
1108+ "Cannot create polymorphic instances with unwrapped values" );
1109+ }
11411110 return _unwrappedPropertyHandler .processUnwrapped (p , ctxt , bean , tokens );
11421111 }
11431112
0 commit comments