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

Read JsonObject directly #14

Open
atomictag opened this issue May 18, 2019 · 6 comments
Open

Read JsonObject directly #14

atomictag opened this issue May 18, 2019 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@atomictag
Copy link

atomictag commented May 18, 2019

Hi there, thanks for this really well-thought library.

In my use case I already have a concrete JsonObject which I want to validate against a schema and apply defaults (withDefaultValues(true)), returning a new validated JsonObject with defaults applied. How can this be achieved with justify? JsonReaderFactory::createReader expects an InputStream or a Reader, but not a JsonObject and I had little luck with JsonParserFactory::createParser which accepts a JsonObject input but I don't seem to manage to collect the stream into another JsonObject. Any help would be greatly appreciated!

@leadpony
Copy link
Owner

Hello @atomictag
Thank you for using this small library.
Unfortunately the current version of this library does not support direct validation of JsonArray or JsonObject in memory. The feature itself is not difficult to implement, because javax.json.stream.JsonParserFactory in JSON-P API 1.1 defines methods createParser(JsonArray) and createParser(JsonObject). But there exists a small problem that neither of the Reference Implementation and Apache Johnzon provide full-fledged parser through these factory methods.
In order to realize the feature, I will try implementing complete parser which parses in-memory JsonArray and JsonObject. Please wait and see the outcome.

@leadpony leadpony self-assigned this May 18, 2019
@leadpony leadpony added the enhancement New feature or request label May 18, 2019
@atomictag
Copy link
Author

Thank you so much. I am about to try out https://github.com/pgelinas/jackson-javax-json to see if that can help (need to switch to Jackson at some point anyway). Thanks again!

@leadpony
Copy link
Owner

Thank you @atomictag, I didn't know about the parser up until now.
To tell the truth, I am currently working on another implementation of JSON-P API from scratch, which provides more robust and faster parser than other implementations. The repo JSON-P Test Suite is built for that purpose.

@atomictag
Copy link
Author

Using a recent version of johnzon-core solved the problem for me

@leadpony
Copy link
Owner

You are right. I confirmed that Johnzon works for it. Thank you for letting me know.
One thing to care: getString() method of in-memory parser in Johnzon has a bug that it wrongly throws an exception when the current value is a number, as my test suite reveals.

leadpony added a commit that referenced this issue May 22, 2019
More tests and performance tuning come later.
leadpony added a commit that referenced this issue May 23, 2019
@leadpony
Copy link
Owner

Hello @atomictag
The latest release 0.17.0 resolved this issue.
I believe both of createParser(JsonArray) and createParser(JsonObject) in JsonParserFactory created by this library, work well with the Reference Implementation besides Apache Johnzon.
However I am not fully satisfied the performance of the current implementation. This library is a streaming style validator and where processing of parsing plus validation is needed,
the library is one of the fastest of all validator implementations for JSON Schema. On the other hand, streaming-style validators are not so good at validating the once-loaded JSON value, because they must produce parser events to be processed from the JSON value before validating it.
The performance issue will be mitigated by coming releases in near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants