Skip to content

Commit 11930a8

Browse files
committed
Fix #700
1 parent 295ed9d commit 11930a8

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ JSON library.
3434
(reported by Fabian M)
3535
#694: Improve exception/JsonLocation handling for binary content: don't
3636
show content, include byte offset
37+
#700: Unable to ignore properties when deserializing. TokenFilter seems broken
38+
(reported by xiazuojie@github)
3739
- Add `mvnw` wrapper
3840

3941
2.12.4 (06-Jul-2021)

src/main/java/com/fasterxml/jackson/core/JsonParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ public boolean isNaN() throws IOException {
14031403
* @param name Name to use as the current name; may be null.
14041404
*/
14051405
public abstract void overrideCurrentName(String name);
1406-
1406+
14071407
/*
14081408
/**********************************************************
14091409
/* Public API, access to token information, text

src/main/java/com/fasterxml/jackson/core/filter/FilteringParserDelegate.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public int getMatchCount() {
184184
public JsonStreamContext getParsingContext() {
185185
return _filterContext();
186186
}
187-
187+
188188
// !!! TODO: Verify it works as expected: copied from standard JSON parser impl
189189
@Override
190190
public String getCurrentName() throws IOException {
@@ -196,6 +196,17 @@ public String getCurrentName() throws IOException {
196196
return ctxt.getCurrentName();
197197
}
198198

199+
// 2.13: IMPORTANT! Must override along with older getCurrentName()
200+
@Override
201+
public String currentName() throws IOException {
202+
JsonStreamContext ctxt = _filterContext();
203+
if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) {
204+
JsonStreamContext parent = ctxt.getParent();
205+
return (parent == null) ? null : parent.getCurrentName();
206+
}
207+
return ctxt.getCurrentName();
208+
}
209+
199210
/*
200211
/**********************************************************
201212
/* Public API, token state overrides
@@ -215,10 +226,9 @@ public void clearCurrentToken() {
215226

216227
@Override
217228
public void overrideCurrentName(String name) {
218-
/* 14-Apr-2015, tatu: Not sure whether this can be supported, and if so,
219-
* what to do with it... Delegation won't work for sure, so let's for
220-
* now throw an exception
221-
*/
229+
// 14-Apr-2015, tatu: Not sure whether this can be supported, and if so,
230+
// what to do with it... Delegation won't work for sure, so let's for
231+
// now throw an exception
222232
throw new UnsupportedOperationException("Can not currently override name during filtering read");
223233
}
224234

@@ -940,5 +950,4 @@ protected JsonStreamContext _filterContext() {
940950
}
941951
return _headContext;
942952
}
943-
944953
}

src/test/java/com/fasterxml/jackson/failing/BasicParserFiltering700Test.java renamed to src/test/java/com/fasterxml/jackson/core/filter/ParserFiltering700Test.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.core.filter;
22

33
import com.fasterxml.jackson.core.*;
4-
import com.fasterxml.jackson.core.filter.FilteringParserDelegate;
5-
import com.fasterxml.jackson.core.filter.TokenFilter;
64
import com.fasterxml.jackson.core.filter.TokenFilter.Inclusion;
75

86
@SuppressWarnings("resource")
9-
public class BasicParserFiltering700Test extends BaseTest
7+
public class ParserFiltering700Test extends BaseTest
108
{
119
static class NoTypeFilter extends TokenFilter {
1210
@Override
@@ -29,14 +27,14 @@ protected boolean _includeScalar() {
2927
/**********************************************************************
3028
*/
3129

32-
private final JsonFactory JSON_F = new JsonFactory();
30+
private final JsonFactory JSON_F = newStreamFactory();
3331

3432
// [core#700], simplified
3533
public void testSkippingRootLevel() throws Exception
3634
{
3735
final String json = a2q("{'@type':'yyy','value':12}");
3836
// should become: {"value":12}
39-
JsonParser p0 = JSON_F.createParser(json);
37+
JsonParser p0 = _createParser(JSON_F, json);
4038
JsonParser p = new FilteringParserDelegate(p0,
4139
new NoTypeFilter(),
4240
Inclusion.INCLUDE_ALL_AND_PATH,
@@ -61,7 +59,7 @@ public void testSkippingOneNested() throws Exception
6159
{
6260
final String json = a2q("{'value':{'@type':'yyy','a':12}}");
6361
// should become: {"value":{"a":12}}
64-
JsonParser p0 = JSON_F.createParser(json);
62+
JsonParser p0 = _createParser(JSON_F, json);
6563
JsonParser p = new FilteringParserDelegate(p0,
6664
new NoTypeFilter(),
6765
Inclusion.INCLUDE_ALL_AND_PATH,
@@ -92,7 +90,7 @@ public void testSkippingForSingleWithPath() throws Exception
9290
final String json = a2q("{'@type':'xxx','value':{'@type':'yyy','a':99}}");
9391
// should become: {"value":{"a":99}}
9492

95-
JsonParser p0 = JSON_F.createParser(json);
93+
JsonParser p0 = _createParser(JSON_F, json);
9694
JsonParser p = new FilteringParserDelegate(p0,
9795
new NoTypeFilter(),
9896
Inclusion.INCLUDE_ALL_AND_PATH,
@@ -116,4 +114,8 @@ public void testSkippingForSingleWithPath() throws Exception
116114

117115
p.close();
118116
}
117+
118+
private JsonParser _createParser(TokenStreamFactory f, String json) throws Exception {
119+
return f.createParser(json);
120+
}
119121
}

0 commit comments

Comments
 (0)