-
-
Notifications
You must be signed in to change notification settings - Fork 148
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 passing ParserImpl
by a subclass or overwrite the events
#482
Allow passing ParserImpl
by a subclass or overwrite the events
#482
Conversation
Makes it possible to overwrite the getEvent calls on the parser to add additional functionality such as filtering, modifying and inserting events. Alternatively provide a constructor to allow using subclasses of the snake yaml ParserImpl. Note: didn't replace the internal parserImpl-field since other subclasses might already use it otherwise would make sense to use the Parser-interface instead.
yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLParser.java
Show resolved
Hide resolved
yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLParser.java
Outdated
Show resolved
Hide resolved
Hmmh. Code doesn't actually... compile. I'll fix it, but going forward it'd be good to at very least build the project before PR. :) |
yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLParser.java
Show resolved
Hide resolved
@HeikoBoettger Made changes to get things to compile & the way I think you meant PR to be. LMK if this is good; I understand the goal and adding overridability is fine. Can go in 2.18.0. |
@cowtowncoder Oh man, I just fired up the github web editor to get this quickly into a PR. I should have taken the time to clone the repository and checkin the actuall file I had locally. The idea with the constructor has a late idea. Sorry for creating so much work on your side, that wasn´t my intention. Thanks for getting this ready. |
@HeikoBoettger no problem; figured it must be something like that. And since it's your first contribution, CI didn't automatically start (to show compilation errors). |
ParserImpl
by a subclass or overwrite the events
Makes it possible to overwrite the getEvent calls on the parser to add additional functionality such as filtering, modifying and inserting events. Alternatively provide a constructor to allow using subclasses of the snake yaml ParserImpl. Note: didn't replace the internal parserImpl-field since other subclasses might already use it otherwise would make sense to use the Parser-interface instead.
Why?
When using networknt/json-schema-validator with yaml files as data input format, I discovered that aliases and merges are not handled in a way that it is possible to validate the yaml files making use of this feature. While there are other discussions in the issue tracker to address this issue, I decided to manipulate the produced JsonTokens by instead of returning a VALUE_STRING producing JsonTolens as if the aliases were inlined the anchor. As it turned out it's simpler to hook into the getEvent-method and do the replacement on the snake yaml parser level. Since the code basically only invoked the getEvent-method of the parser in one place, I decided to extract a protected-method to overwrite it in my own code. This is the easiest way having to contribute a larger piece of code or having to completely copy the nextToken-method into my subclass.
Optionally I was thinking of injecting a subclass off the ParserImpl however that's also not possible, so I provide this option as well leaving other the choice how to extend the class.