Skip to content

Commit 93afe52

Browse files
authored
Post #4690 clean up wrt early exit from deser loop (#5448)
1 parent 1b8b323 commit 93afe52

File tree

4 files changed

+19
-23
lines changed

4 files changed

+19
-23
lines changed

src/main/java/tools/jackson/databind/deser/CreatorProperty.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ public boolean isInjectionOnly() {
276276

277277
// public boolean isInjectionOnly() { return false; }
278278

279+
@Override // @since 3.1
280+
public boolean isCreatorProperty() { return true; }
281+
279282
/*
280283
/**********************************************************************
281284
/* Overridden methods, other

src/main/java/tools/jackson/databind/deser/SettableBeanProperty.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,6 @@ public void markAsIgnorable() { }
354354

355355
/**
356356
* Whether this property requires merging of values (read-then-write)
357-
*
358-
* @since 2.20
359357
*/
360358
public boolean isMerging() {
361359
// Most are not merging so default to this implementation
@@ -488,6 +486,11 @@ public int getCreatorIndex() {
488486
*/
489487
public boolean isInjectionOnly() { return false; } // overridden by CreatorProperty
490488

489+
/**
490+
* Since 3.1
491+
*/
492+
public boolean isCreatorProperty() { return false; } // overridden by CreatorProperty
493+
491494
/*
492495
/**********************************************************************
493496
/* Public API
@@ -778,6 +781,9 @@ public void fixAccess(DeserializationConfig config) {
778781
@Override
779782
public boolean isInjectionOnly() { return delegate.isInjectionOnly(); }
780783

784+
@Override
785+
public boolean isCreatorProperty() { return delegate.isCreatorProperty(); }
786+
781787
@Override
782788
public AnnotatedMember getMember() {
783789
return delegate.getMember();

src/main/java/tools/jackson/databind/deser/bean/BeanDeserializer.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,24 +1261,10 @@ protected Object deserializeUsingPropertyBasedWithExternalTypeId(JsonParser p, D
12611261
// since it is not the bean
12621262
if (!ext.handlePropertyValue(p, ctxt, propName, null)) {
12631263
// Last creator property to set?
1264-
if (buffer.assignParameter(creatorProp, _deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
1265-
t = p.nextToken(); // to move to following PROPERTY_NAME/END_OBJECT
1266-
Object bean;
1267-
try {
1268-
bean = creator.build(ctxt, buffer);
1269-
} catch (Exception e) {
1270-
throw wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
1271-
}
1272-
if (bean.getClass() != _beanType.getRawClass()) {
1273-
// !!! 08-Jul-2011, tatu: Could theoretically support; but for now
1274-
// it's too complicated, so bail out
1275-
return ctxt.reportBadDefinition(_beanType, String.format(
1276-
"Cannot create polymorphic instances with external type ids (%s -> %s)",
1277-
_beanType, bean.getClass()));
1278-
}
1279-
// 19-Feb-2021, tatu: [databind#3045] Better delegate
1280-
return _deserializeWithExternalTypeId(p, ctxt, bean, ext);
1281-
}
1264+
// [databind#4690] cannot quit early as optimization any more
1265+
// if (buffer.assignParameter(creatorProp, value)) { ... build ... }
1266+
buffer.assignParameter(creatorProp,
1267+
_deserializeWithErrorWrapping(p, ctxt, creatorProp));
12821268
}
12831269
continue;
12841270
}

src/main/java/tools/jackson/databind/deser/impl/ExternalTypeHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import tools.jackson.core.*;
66
import tools.jackson.databind.*;
7+
import tools.jackson.databind.deser.CreatorProperty;
78
import tools.jackson.databind.deser.SettableBeanProperty;
89
import tools.jackson.databind.deser.bean.BeanPropertyMap;
910
import tools.jackson.databind.deser.bean.PropertyBasedCreator;
@@ -303,13 +304,13 @@ public Object complete(JsonParser p, DeserializationContext ctxt,
303304

304305
final SettableBeanProperty prop = extProp.getProperty();
305306
// also: if it's creator prop, fill in
306-
if (prop.getCreatorIndex() >= 0) {
307+
if (prop.isCreatorProperty()) {
307308
buffer.assignParameter(prop, values[i]);
308309

309310
// [databind#999] And maybe there's creator property for type id too?
310311
SettableBeanProperty typeProp = extProp.getTypeProperty();
311312
// for now, should only be needed for creator properties, too
312-
if ((typeProp != null) && (typeProp.getCreatorIndex() >= 0)) {
313+
if (typeProp != null && typeProp.isCreatorProperty()) {
313314
// 31-May-2018, tatu: [databind#1328] if id is NOT plain `String`, need to
314315
// apply deserializer... fun fun.
315316
final Object v;
@@ -329,7 +330,7 @@ public Object complete(JsonParser p, DeserializationContext ctxt,
329330
// third: assign non-creator properties
330331
for (int i = 0; i < len; ++i) {
331332
SettableBeanProperty prop = _properties[i].getProperty();
332-
if (prop.getCreatorIndex() < 0) {
333+
if (!prop.isCreatorProperty()) {
333334
prop.set(ctxt, bean, values[i]);
334335
}
335336
}

0 commit comments

Comments
 (0)