Skip to content

Commit 644831c

Browse files
committed
Fix #2088
1 parent 63d48ff commit 644831c

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Project: jackson-databind
1212
#2079: NPE when visiting StaticListSerializerBase
1313
(reported by WorldSEnder@github)
1414
#2082: `FactoryBasedEnumDeserializer` should be cachable
15+
#2088: `@JsonUnwrapped` fields are skipped when using `PropertyBasedCreator` if
16+
they appear after the last creator property
17+
(reported, fix contributed by 6bangs@github)
1518
#2096: `TreeTraversingParser` does not take base64 variant into account
1619
(reported by tangiel@github)
1720
#2097: Block more classes from polymorphic deserialization (CVE-2018-14718

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -767,10 +767,17 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p, Deseri
767767
p.setCurrentValue(bean);
768768
// if so, need to copy all remaining tokens into buffer
769769
while (t == JsonToken.FIELD_NAME) {
770-
p.nextToken(); // to skip name
770+
// NOTE: do NOT skip name as it needs to be copied; `copyCurrentStructure` does that
771771
tokens.copyCurrentStructure(p);
772772
t = p.nextToken();
773773
}
774+
// 28-Aug-2018, tatu: Let's add sanity check here, easier to catch off-by-some
775+
// problems if we maintain invariants
776+
if (t != JsonToken.END_OBJECT) {
777+
ctxt.reportWrongTokenException(this, JsonToken.END_OBJECT,
778+
"Attempted to unwrap '%s' value",
779+
handledType().getName());
780+
}
774781
tokens.writeEndObject();
775782
if (bean.getClass() != _beanType.getRawClass()) {
776783
// !!! 08-Jul-2011, tatu: Could probably support; but for now

src/test/java/com/fasterxml/jackson/databind/struct/TestUnwrapped.java

+38
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,34 @@ static class Address {
111111
public String country;
112112
}
113113

114+
// [databind#2088]
115+
static class Issue2088Bean {
116+
int x;
117+
int y;
118+
119+
@JsonUnwrapped
120+
Issue2088UnwrappedBean w;
121+
122+
public Issue2088Bean(@JsonProperty("x") int x, @JsonProperty("y") int y) {
123+
this.x = x;
124+
this.y = y;
125+
}
126+
127+
public void setW(Issue2088UnwrappedBean w) {
128+
this.w = w;
129+
}
130+
}
131+
132+
static class Issue2088UnwrappedBean {
133+
int a;
134+
int b;
135+
136+
public Issue2088UnwrappedBean(@JsonProperty("a") int a, @JsonProperty("b") int b) {
137+
this.a = a;
138+
this.b = b;
139+
}
140+
}
141+
114142
/*
115143
/**********************************************************
116144
/* Tests, serialization
@@ -215,4 +243,14 @@ public void testCaseInsensitiveUnwrap() throws Exception
215243
Person p = mapper.readValue("{ }", Person.class);
216244
assertNotNull(p);
217245
}
246+
247+
// [databind#2088]: accidental skipping of values
248+
public void testIssue2088UnwrappedFieldsAfterLastCreatorProp() throws Exception
249+
{
250+
Issue2088Bean bean = MAPPER.readValue("{\"x\":1,\"a\":2,\"y\":3,\"b\":4}", Issue2088Bean.class);
251+
assertEquals(1, bean.x);
252+
assertEquals(2, bean.w.a);
253+
assertEquals(3, bean.y);
254+
assertEquals(4, bean.w.b);
255+
}
218256
}

0 commit comments

Comments
 (0)