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 passing ParserImpl by a subclass or overwrite the events #482

Conversation

HeikoBoettger
Copy link
Contributor

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.

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.
@HeikoBoettger HeikoBoettger changed the base branch from 2.18 to master July 19, 2024 12:33
@HeikoBoettger HeikoBoettger changed the base branch from master to 2.18 July 19, 2024 12:33
@cowtowncoder
Copy link
Member

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. :)

@cowtowncoder
Copy link
Member

@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.

@HeikoBoettger
Copy link
Contributor Author

@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.

@cowtowncoder
Copy link
Member

@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).

@cowtowncoder cowtowncoder changed the title Allow to replace the ParserImpl by a subclass or overwrite the events Allow passing ParserImpl by a subclass or overwrite the events Jul 21, 2024
@cowtowncoder cowtowncoder merged commit c94cb96 into FasterXML:2.18 Jul 21, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants