Skip to content

Commit 2afa5c9

Browse files
committed
Fix #3252, regression between 2.12 and 2.13.0-rc1
1 parent 074cd30 commit 2afa5c9

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,17 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
499499
// 29-Mar-2021, tatu: [databind#3082] May skip collection if we know
500500
// they'd just get ignored (note: any-setter handled above; unwrapped
501501
// properties also separately handled)
502-
if (!_ignoreAllUnknown) {
503-
// Ok then, let's collect the whole field; name and value
504-
if (unknown == null) {
505-
unknown = ctxt.bufferForInputBuffering(p);
506-
}
507-
unknown.writeFieldName(propName);
508-
unknown.copyCurrentStructure(p);
502+
if (_ignoreAllUnknown) {
503+
// 22-Aug-2021, tatu: [databind#3252] must ensure we do skip the whole value
504+
p.skipChildren();
505+
continue;
506+
}
507+
// Ok then, let's collect the whole field; name and value
508+
if (unknown == null) {
509+
unknown = ctxt.bufferForInputBuffering(p);
509510
}
511+
unknown.writeFieldName(propName);
512+
unknown.copyCurrentStructure(p);
510513
}
511514

512515
// We hit END_OBJECT, so:

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,6 @@ protected void handleUnknownVanilla(JsonParser p, DeserializationContext ctxt,
16641664
Object beanOrBuilder, String propName)
16651665
throws IOException
16661666
{
1667-
16681667
if (IgnorePropertiesUtil.shouldIgnore(propName, _ignorableProps, _includableProps)) {
16691668
handleIgnoredProperty(p, ctxt, beanOrBuilder, propName);
16701669
} else if (_anySetter != null) {

src/test/java/com/fasterxml/jackson/databind/deser/creators/CreatorPropertiesTest.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package com.fasterxml.jackson.databind.deser.creators;
22

33
import java.beans.ConstructorProperties;
4+
import java.util.Collections;
5+
import java.util.List;
6+
import java.util.Map;
47

58
import com.fasterxml.jackson.annotation.*;
9+
10+
import com.fasterxml.jackson.core.type.TypeReference;
11+
612
import com.fasterxml.jackson.databind.*;
713

814
public class CreatorPropertiesTest extends BaseMapTest
@@ -58,13 +64,29 @@ public Lombok1371Bean(int _x, int _y) {
5864
}
5965
}
6066

67+
// [databind#3252]: ensure full skipping of ignored properties
68+
@JsonIgnoreProperties(ignoreUnknown = true)
69+
public static class Value3252 {
70+
@JsonProperty("name")
71+
private final String name;
72+
@JsonProperty("dumbMap")
73+
private final Map<String, String> dumbMap;
74+
75+
@JsonCreator
76+
public Value3252(@JsonProperty("name") String name,
77+
@JsonProperty("dumbMap") Map<String, String> dumbMap) {
78+
this.name = name;
79+
this.dumbMap = (dumbMap == null) ? Collections.emptyMap() : dumbMap;
80+
}
81+
}
82+
6183
/*
6284
/**********************************************************
6385
/* Test methods
6486
/**********************************************************
6587
*/
6688

67-
private final ObjectMapper MAPPER = new ObjectMapper();
89+
private final ObjectMapper MAPPER = newJsonMapper();
6890

6991
// [databind#905]
7092
public void testCreatorPropertiesAnnotation() throws Exception
@@ -104,4 +126,19 @@ public void testConstructorPropertiesInference() throws Exception
104126
assertEquals(3, result.x);
105127
assertEquals(5, result.y);
106128
}
129+
130+
// [databind#3252]: ensure full skipping of ignored properties
131+
public void testSkipNonScalar3252() throws Exception
132+
{
133+
List<Value3252> testData = MAPPER.readValue(a2q(
134+
"[\n"+
135+
" {'name': 'first entry'},\n"+
136+
" {'name': 'second entry', 'breaker': ['' ]},\n"+
137+
" {'name': 'third entry'}\n"+
138+
" ]\n"),
139+
new TypeReference<List<Value3252>>() {});
140+
141+
//System.err.println("JsON: "+MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(testData));
142+
assertEquals(3, testData.size());
143+
}
107144
}

0 commit comments

Comments
 (0)