-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
More customizable TokenFilter inclusion (using Tokenfilter.Inclusion
)
#573
Conversation
Ok updated to support parsing as well. One of the tests I added for parsing is failing, but it appears to also fail on master so I don't think it's related to my changes. Here's the failing test you can add to public void testExcludeArrays() throws Exception
{
class NoArraysFilter extends TokenFilter
{
@Override
public TokenFilter filterStartArray() {
return null;
}
}
String jsonString = aposToQuotes("{'a':123,'array':[1,2]}");
JsonParser p0 = JSON_F.createParser(jsonString);
FilteringParserDelegate p = new FilteringParserDelegate(p0,
new NoArraysFilter(),
true, // includePath
true // multipleMatches
);
String result = readAndWrite(JSON_F, p);
assertEquals(aposToQuotes("{'a':123}"), result);
assertEquals(1, p.getMatchCount());
} When I run it I get:
So it's generating invalid JSON. I'm not seeing anything wrong with the logic of the test, and the same test works on the |
@jhaber apologies for slow follow up. I added this on my short (?) list of things to do (https://github.com/FasterXML/jackson-future-ideas/wiki/Jackson-Work-in-Progress) and will try to review soon. There is also minor (I hope) merge conflict, related to fix for #582. |
No worries, I'll get that merge conflict fixed in the meantime |
Merge conflict addressed |
@jhaber I seem to have dropped the ball here... and so this can't go in 2.11 any more (since that is in patch mode). |
Sounds good, I can try to rebase before end of week |
Excellent! |
Updated this PR to target 2.12 branch. Luckily there are no conflicts so that's all there was to it |
Hmmh. Looks like there are 2 new test failures; one for parser filtering, another for generator; filtering generator produces invalid output ( |
Sorry about that, I'll take a look over the weekend. I mentioned above about a similar quirk I noticed, but it failed the same way without my changes so I didn't dig into it too deeply |
@jhaber np. I'll leave changes in 2.12 branch, will see if you can spot what might be going on. Not sure why PR build didn't catch this on Travis (but they seem to have had issues). |
Opened #650 to fix these tests |
Tokenfilter.Inclusion
)
Related to #572
There is a new enum that makes the behavior of
FilteringGeneratorDelegate
more customizable. I first called this enumPathWriteMode
, since it replaces the_includePath
flag. The options wereNONE
(equivalent to_includePath=false
),LAZY
(equivalent to_includePath=true
), orEAGER
(write tokens immediately unless a nullTokenFilter
is returned). However, LAZY/EAGER are very tied to howFilteringGeneratorDelegate
is implemented and may not make intuitive sense unless you're familiar with the implementation.I realized that an equivalent way to think about this is in terms of how
TokenFilter
return values should be interpreted. In particular, what does it mean to return a filter that is neithernull
norINCLUDE_ALL
? It seems like the options are:_includePath=false
)INCLUDE_ALL
(equivalent to_includePath=true
)So I made the enum
TokenFilter.Inclusion
inside ofTokenFilter
with options ofONLY_INCLUDE_ALL
,INCLUDE_ALL_AND_PATH
, orINCLUDE_NON_NULL
. I'm also realizing that this enum could apply equally toFilteringParserDelegate
, so these changes should probably support both reading and writing. I can work on that next, just wanted to make sure everything makes sense so far