Skip to content

Commit c9f36d9

Browse files
committed
Fix #2415
1 parent 41b976c commit c9f36d9

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

release-notes/CREDITS-2.x

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,3 +900,9 @@ Victor Noël (victornoel@github)
900900
Chris Mercer (cmercer@github)
901901
* Reported #2331: `JsonMappingException` through nested getter with generic wildcard return type
902902
(2.10.0)
903+
904+
Vladimir Tsanev (tsachev@github)
905+
* Contributed #2415: Builder-based POJO deserializer should pass builder instance, not type,
906+
to `handleUnknownVanilla()` to fix earlier #822
907+
(2.10.0)
908+

release-notes/VERSION-2.x

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ Project: jackson-databind
1414
(reported by andreasbaus@github)
1515
#2393: `TreeTraversingParser.getLongValue()` incorrectly checks `canConvertToInt()`
1616
(reported by RabbidDog@github)
17-
#2416: Optimize `ValueInstantiator` construction for default `Collection`, `Map` types
17+
#2415: Builder-based POJO deserializer should pass builder instance, not type,
18+
to `handleUnknownVanilla()`
19+
(proposed by Vladimir T, follow up to #822)
20+
#2416: Optimize `ValueInstantiator` construction for default `Collection`, `Map` types
1821

1922
2.10.0.pr1 (19-Jul-2019)
2023

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,23 +1548,27 @@ protected Object handleUnknownProperties(DeserializationContext ctxt,
15481548
/**
15491549
* Helper method called for an unknown property, when using "vanilla"
15501550
* processing.
1551+
*
1552+
* @param beanOrBuilder Either POJO instance (if constructed), or builder
1553+
* (in case of builder-based approach), that has property we haven't been
1554+
* able to handle yet.
15511555
*/
15521556
protected void handleUnknownVanilla(JsonParser p, DeserializationContext ctxt,
1553-
Object bean, String propName)
1557+
Object beanOrBuilder, String propName)
15541558
throws IOException
15551559
{
15561560
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
1557-
handleIgnoredProperty(p, ctxt, bean, propName);
1561+
handleIgnoredProperty(p, ctxt, beanOrBuilder, propName);
15581562
} else if (_anySetter != null) {
15591563
try {
15601564
// should we consider return type of any setter?
1561-
_anySetter.deserializeAndSet(p, ctxt, bean, propName);
1565+
_anySetter.deserializeAndSet(p, ctxt, beanOrBuilder, propName);
15621566
} catch (Exception e) {
1563-
wrapAndThrow(e, bean, propName, ctxt);
1567+
wrapAndThrow(e, beanOrBuilder, propName, ctxt);
15641568
}
15651569
} else {
15661570
// Unknown: let's call handler method
1567-
handleUnknownProperty(p, ctxt, bean, propName);
1571+
handleUnknownProperty(p, ctxt, beanOrBuilder, propName);
15681572
}
15691573
}
15701574

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ protected final Object _deserialize(JsonParser p,
468468
}
469469
continue;
470470
}
471-
handleUnknownVanilla(p, ctxt, handledType(), propName);
471+
handleUnknownVanilla(p, ctxt, builder, propName);
472472
}
473473
return builder;
474474
}

src/test/java/com/fasterxml/jackson/databind/deser/builder/BuilderSimpleTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,11 @@ static class ValueBuilder822
216216
{
217217
public int x;
218218
private Map<String,Object> stuff = new HashMap<String,Object>();
219-
220-
public ValueBuilder822 withX(int x0) {
219+
220+
// And tweaked slightly for [databind#2415]
221+
@JsonCreator
222+
public ValueBuilder822(@JsonProperty("x") int x0) {
221223
this.x = x0;
222-
return this;
223224
}
224225

225226
@JsonAnySetter

0 commit comments

Comments
 (0)