erosb / json-sKema

JSON Schema Validator for the JVM, implements draft2020-12
MIT License
53 stars 10 forks source link

Proposal to use existing JSON Object models #117

Open ferozed opened 1 month ago

ferozed commented 1 month ago

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 commented 1 month ago

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.