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

Fix for issue 209 - make use of _allowMultipleMatches FilterParsingDelegate #262

Closed
wants to merge 1 commit into from
Closed
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 @@ -221,6 +221,13 @@ public void overrideCurrentName(String name) {
@Override
public JsonToken nextToken() throws IOException
{
//Check for _allowMultipleMatches - false and atleast there is one token - which is _currToken
// and check for _itemFilter matching INCLUDE_ALL.
//If all the conditions matches then return null
if(!_allowMultipleMatches && _currToken != null
&& _itemFilter == TokenFilter.INCLUDE_ALL){
return null;
}
// Anything buffered?
TokenFilterContext ctxt = _exposedContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,35 @@ public void testSingleMatchFilteringWithPath() throws Exception
assertEquals(aposToQuotes("{'ob':{'value':3}}"), result);
}


@SuppressWarnings("resource")
public void testNotAllowMultipleMatches() throws Exception
{
String jsonString = aposToQuotes("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4},'value':4,'b':true}");
JsonParser p0 = JSON_F.createParser(jsonString);
JsonParser p = new FilteringParserDelegate(p0,
new NameMatchFilter("value"),
false, // includePath
false // multipleMatches -false
);
String result = readAndWrite(JSON_F, p);
assertEquals(aposToQuotes("3"), result);
}

@SuppressWarnings("resource")
public void testAllowMultipleMatches() throws Exception
{
String jsonString = aposToQuotes("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4},'value':4,'b':true}");
JsonParser p0 = JSON_F.createParser(jsonString);
JsonParser p = new FilteringParserDelegate(p0,
new NameMatchFilter("value"),
false, // includePath
true // multipleMatches - true
);
String result = readAndWrite(JSON_F, p);
assertEquals(aposToQuotes("3 4"), result);
}

@SuppressWarnings("resource")
public void testMultipleMatchFilteringWithPath1() throws Exception
{
Expand Down