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

Proposal to use existing JSON Object models #117

Open
ferozed opened this issue Oct 14, 2024 · 1 comment
Open

Proposal to use existing JSON Object models #117

ferozed opened this issue Oct 14, 2024 · 1 comment

Comments

@ferozed
Copy link

ferozed commented Oct 14, 2024

I have a suggestion. The validator is using it's own object classes JsonParser and JsonValue.

The issue is that when a service needs to parse the payload for it's own needs, the parse will be done two times. Once by the service and once for the validator.

If we can use existing json parsers like jackson or Gson then we can parse it once and hand the parsed tree to the validator

@erosb
Copy link
Owner

erosb commented Oct 14, 2024

Hello @ferozed , relying on an external library for json parsing was intentionally avoided in this library. The predecessor library uses the JSON-Java project and it caused problems in multiple ways. Moreover, last time when I looked at jackson, I couldn't find any way to obtain the line number & character position from the original json source (which this library uses in its validation error reports).

If you need to map an external json model (either jackson or gson), I suggest, instead of re-parsing, just mapping from one object model to an other.

Actually, in 0.19.0-RC1 which was released today morning, this library does the same when mapping from snakeyaml model to JsonValue , you can use it for reference. If you can keep the line number + character position info, like in this snakeyaml mapper function, then even better.

Your concern about re-parsing is definitely valid, better to avoid that.

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

No branches or pull requests

2 participants