Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow FilteringParserDelegate to skip last elements in array #883

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,9 @@ protected final JsonToken _nextTokenWithBuffering(final TokenFilterContext buffR
if (returnEnd) {
return t;
}
if (gotEnd) {
return null;
}
}
continue main_loop;
case ID_END_OBJECT:
Expand Down Expand Up @@ -781,6 +784,9 @@ protected final JsonToken _nextTokenWithBuffering(final TokenFilterContext buffR
if (returnEnd) {
return t;
}
if (gotEnd) {
return null;
}
}
continue main_loop;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,4 +719,48 @@ public void testIncludeEmptyArrayIfNotFilteredAfterFiltered() throws Exception {
);
assertEquals(a2q("[{'empty_array':[]}]"), readAndWrite(JSON_F, p));
}

public void testExcludeObjectAtTheBeginningOfArray() throws Exception {
JsonParser p0 = JSON_F.createParser(a2q(
"{'parent':[{'exclude':false},{'include':true}]}"));
JsonParser p = new FilteringParserDelegate(p0,
new NameMatchFilter(new String[] { "include" } ),
Inclusion.INCLUDE_ALL_AND_PATH,
false // multipleMatches
);
assertEquals(a2q("{'parent':[{'include':true}]}"), readAndWrite(JSON_F, p));
}

public void testExcludeObjectAtTheEndOfArray() throws Exception {
JsonParser p0 = JSON_F.createParser(a2q(
"{'parent':[{'include':true},{'exclude':false}]}"));
JsonParser p = new FilteringParserDelegate(p0,
new NameMatchFilter(new String[] { "include" } ),
Inclusion.INCLUDE_ALL_AND_PATH,
false // multipleMatches
);
assertEquals(a2q("{'parent':[{'include':true}]}"), readAndWrite(JSON_F, p));
}

public void testExcludeObjectInMiddleOfArray() throws Exception {
JsonParser p0 = JSON_F.createParser(a2q(
"{'parent':[{'include-1':1},{'skip':0},{'include-2':2}]}"));
JsonParser p = new FilteringParserDelegate(p0,
new NameMatchFilter(new String[]{"include-1", "include-2"}),
Inclusion.INCLUDE_ALL_AND_PATH,
true // multipleMatches
);
assertEquals(a2q("{'parent':[{'include-1':1},{'include-2':2}]}"), readAndWrite(JSON_F, p));
}

public void testExcludeLastArrayInsideArray() throws Exception {
JsonParser p0 = JSON_F.createParser(a2q(
"['skipped', [], ['skipped']]"));
JsonParser p = new FilteringParserDelegate(p0,
INCLUDE_EMPTY_IF_NOT_FILTERED,
Inclusion.INCLUDE_ALL_AND_PATH,
true // multipleMatches
);
assertEquals(a2q("[[]]"), readAndWrite(JSON_F, p));
}
}