-
-
Notifications
You must be signed in to change notification settings - Fork 812
Allow TokenFilter to preserve empty #716
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
Conversation
OK! I've got my tests working for this, but, like I said on the issue, I don't know the code base and very well could be screwing things up in ways I don't understand. I haven't tested this with |
This creates two new method on `TokenFilter` which you can override to decide if empty arrays and objects should be included or excluded. An override like this, for example, will include all arrays and objects that were sent empty but strip any arrays or objects that were *filtered* to be empty: ``` @OverRide public boolean includeEmptyArray(boolean contentsFiltered) { return !contentsFiltered; } @OverRide public boolean includeEmptyObject(boolean contentsFiltered) { return !contentsFiltered; } ``` The default to preserve backwards compatibility is to always *exclude* empty objects. Closes FasterXML#715
@@ -451,11 +451,15 @@ protected String readAndWrite(JsonFactory f, JsonParser p) throws IOException | |||
g.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT); | |||
try { | |||
while (p.nextToken() != null) { | |||
System.err.println(p.currentToken() + " " + p.currentName() + " " + p.currentValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left this in to remind myself to ask about currentName
on the tokens to close objects. Have a look at what this prints in some of the tests. I'm not sure that currentName
has the value you'd expect there. I don't think I use it in that context, but I wanted to bring it up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just make sure this gets removed before merging -- no System.err or System.out output from Jackson code ever unless absolutely required.
throw new AssertionError( | ||
"Unexpected problem during `readAndWrite`. Output so far: '" + | ||
sw + "'; problem: " + e.getMessage(), | ||
e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't required at all but it sure made all the failures easier to see. I had a lot of failures.....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But isn't there already fail()
call there? Is this to get stack trace or ... ?
{ | ||
boolean returnEnd = _headContext.isStartHandled(); | ||
f = _headContext.getFilter(); | ||
if ((f != null) && (f != TokenFilter.INCLUDE_ALL)) { | ||
boolean includeEmpty = f.includeEmptyArray(_headContext.hasCurrentIndex()); | ||
f.filterFinishArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in the old code this was calling the wrong callback here.
Hello! It's been a while. I'm still quite interested in this if any maintainers are willing to work with me. |
Hi @nik9000 ! Thank you for pinging me. I have had less time on Jackson lately, but hoping to pick up things now. |
@nik9000 Apologies for dropping this from 2.13, but I am now back working on getting 2.14 branch going; and I would be interested in getting this patch in. Could you rebase this PR against 2.14? |
I'll give it a go soon!
…On Sat, Dec 4, 2021, 9:39 PM Tatu Saloranta ***@***.***> wrote:
@nik9000 <https://github.com/nik9000> Apologies for dropping this from
2.13, but I am now back working on getting 2.14 branch going; and I would
be interested in getting this patch in. Could you rebase this PR against
2.14?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#716 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABUXIU5HPKREAJGFA4QOCLUPLGH5ANCNFSM5D4KCWMQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
I opened #729. |
This creates two new method on
TokenFilter
which you can override todecide if empty arrays and objects should be included or excluded. An
override like this, for example, will include all arrays and objects
that were sent empty but strip any arrays or objects that were
filtered to be empty:
The default to preserve backwards compatibility is to always exclude
empty objects.
Closes #715