-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Non blocking JSON parser #2106
Non blocking JSON parser #2106
Conversation
+1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments/concerns. Otherwise, great work!
@@ -117,10 +117,12 @@ | |||
<dependency> | |||
<groupId>com.fasterxml.jackson.core</groupId> | |||
<artifactId>jackson-core</artifactId> | |||
<version>2.9.0</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we update the BOM (vertx-dependencies
) rather than this POM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it will be, before merging that PR, I'll update the vertx-dependencies, for now it's hardcoded here.
And it's not a BOM :-)
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.9.0</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, BOM vs POM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not a BOM again :-)
== Json Parser | ||
|
||
You can easily parse JSON structures but that requires to provide the JSON string at once, but it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: JSON content instead of JSON string. It's not always a string, it can be a buffer as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the buffer is encoded as a JSON string though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok, I see what you mean :-)
---- | ||
|
||
The parser is non-blocking and emitted events are driven by the input buffers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: missing final dot.
// start object event | ||
// "firstName":"Bob" event | ||
parser.handle(Buffer.buffer("[{\"firstName\":\"Bob\"},")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the end parenthesis shouldn't be there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's valid java code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the Java code compiles. I was wondering if the parenthesis inside the JSON content would not trigger an end object event. Am I wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see parenthesis in JSON content
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean curly brace ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha. Yeah, I meant curly brace. Sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the content was wrong, I think I fixed it now
---- | ||
|
||
Event driven parsing provides more control but comes at the price of flexibility. The parser allows you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why at the price of flexibility? If the parser gives your more control, doesn't this make it more flexible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to convey that if you deal with fine grained events, it becomes harder to parse because you have to care about lot of individual events which can be inconvenient, I will try to say that differently.
switch (event.type()) { | ||
case START_OBJECT: | ||
// Set object value mode to handle each entry, from now on the parser won't emit start object events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, when object value mode is enabled, all nested objects/arrays are parsed at once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just reviewed the parser impl, it seems to be the case. Could you add tests for nested objects/arrays?
* @throws java.lang.ClassCastException if the value is not a String | ||
* @throws java.time.format.DateTimeParseException if the String value is not a legal ISO 8601 encoded value | ||
*/ | ||
Instant instantValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought Instant
didn't work with codegen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I'm going to add "@GenIgnore", I was testing using the IDE that does not run the annotation processor but in reality it fails :-)
START_ARRAY, | ||
|
||
/** | ||
* Signals the end of a JSON object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
object => array
* @return a reference to this, so the API can be used fluently | ||
*/ | ||
@Fluent | ||
JsonParser arrayValueMode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add doc/example for this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
PTAL |
Event driven parsing provides more control but comes at the price of flexibility. The parser allows you | ||
to handle JSON structures as values when it is desired: | ||
Event driven parsing provides more control but comes at the price of dealing with fine grained events, which can be | ||
inconvenient sometimes. The JSON parser allows you to handle JSON structures as values when it is desired: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -103,17 +103,17 @@ JsonParser parser = JsonParser.newParser(); | |||
// start array event | |||
// start object event | |||
// "firstName":"Bob" event | |||
parser.handle(Buffer.buffer("[{\"firstName\":\"Bob\"},")); | |||
parser.handle(Buffer.buffer("[{\"firstName\":\"Bob\",")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
LGTM. I can't merge (permissions issue we talk about yesterday) but anyway you have to update the |
Provide an event driven and non blocking JSON parser that can also be used as a read stream. The parser can emit fine grained events for JSON structures or emit them as values in a dynamic fashio.