Skip to content

Commit

Permalink
Fix #700
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 20, 2021
1 parent 295ed9d commit 11930a8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ JSON library.
(reported by Fabian M)
#694: Improve exception/JsonLocation handling for binary content: don't
show content, include byte offset
#700: Unable to ignore properties when deserializing. TokenFilter seems broken
(reported by xiazuojie@github)
- Add `mvnw` wrapper

2.12.4 (06-Jul-2021)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/fasterxml/jackson/core/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ public boolean isNaN() throws IOException {
* @param name Name to use as the current name; may be null.
*/
public abstract void overrideCurrentName(String name);

/*
/**********************************************************
/* Public API, access to token information, text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public int getMatchCount() {
public JsonStreamContext getParsingContext() {
return _filterContext();
}

// !!! TODO: Verify it works as expected: copied from standard JSON parser impl
@Override
public String getCurrentName() throws IOException {
Expand All @@ -196,6 +196,17 @@ public String getCurrentName() throws IOException {
return ctxt.getCurrentName();
}

// 2.13: IMPORTANT! Must override along with older getCurrentName()
@Override
public String currentName() throws IOException {
JsonStreamContext ctxt = _filterContext();
if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) {
JsonStreamContext parent = ctxt.getParent();
return (parent == null) ? null : parent.getCurrentName();
}
return ctxt.getCurrentName();
}

/*
/**********************************************************
/* Public API, token state overrides
Expand All @@ -215,10 +226,9 @@ public void clearCurrentToken() {

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

Expand Down Expand Up @@ -940,5 +950,4 @@ protected JsonStreamContext _filterContext() {
}
return _headContext;
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.fasterxml.jackson.failing;
package com.fasterxml.jackson.core.filter;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.filter.FilteringParserDelegate;
import com.fasterxml.jackson.core.filter.TokenFilter;
import com.fasterxml.jackson.core.filter.TokenFilter.Inclusion;

@SuppressWarnings("resource")
public class BasicParserFiltering700Test extends BaseTest
public class ParserFiltering700Test extends BaseTest
{
static class NoTypeFilter extends TokenFilter {
@Override
Expand All @@ -29,14 +27,14 @@ protected boolean _includeScalar() {
/**********************************************************************
*/

private final JsonFactory JSON_F = new JsonFactory();
private final JsonFactory JSON_F = newStreamFactory();

// [core#700], simplified
public void testSkippingRootLevel() throws Exception
{
final String json = a2q("{'@type':'yyy','value':12}");
// should become: {"value":12}
JsonParser p0 = JSON_F.createParser(json);
JsonParser p0 = _createParser(JSON_F, json);
JsonParser p = new FilteringParserDelegate(p0,
new NoTypeFilter(),
Inclusion.INCLUDE_ALL_AND_PATH,
Expand All @@ -61,7 +59,7 @@ public void testSkippingOneNested() throws Exception
{
final String json = a2q("{'value':{'@type':'yyy','a':12}}");
// should become: {"value":{"a":12}}
JsonParser p0 = JSON_F.createParser(json);
JsonParser p0 = _createParser(JSON_F, json);
JsonParser p = new FilteringParserDelegate(p0,
new NoTypeFilter(),
Inclusion.INCLUDE_ALL_AND_PATH,
Expand Down Expand Up @@ -92,7 +90,7 @@ public void testSkippingForSingleWithPath() throws Exception
final String json = a2q("{'@type':'xxx','value':{'@type':'yyy','a':99}}");
// should become: {"value":{"a":99}}

JsonParser p0 = JSON_F.createParser(json);
JsonParser p0 = _createParser(JSON_F, json);
JsonParser p = new FilteringParserDelegate(p0,
new NoTypeFilter(),
Inclusion.INCLUDE_ALL_AND_PATH,
Expand All @@ -116,4 +114,8 @@ public void testSkippingForSingleWithPath() throws Exception

p.close();
}

private JsonParser _createParser(TokenStreamFactory f, String json) throws Exception {
return f.createParser(json);
}
}

0 comments on commit 11930a8

Please sign in to comment.