See: Description
Interface | Description |
---|---|
JsonEvent |
A JSON event emited by the
JsonParser . |
JsonParser |
A parser class which allows to incrementally parse json elements and emit json parse events instead of parsing a json
element fully.
|
RecordParser |
A helper class which allows you to easily parse protocols which are delimited by a sequence of bytes, or fixed
size records.
|
Enum | Description |
---|---|
JsonEventType |
The possibles types of
JsonEvent emitted by the JsonParser . |
examples.ParseToolsExamples#recordParserExample1()
----
You can also produce fixed sized chunks as follows:
[source, $lang]
----
examples.ParseToolsExamples#recordParserExample2()
----
For more details, check out the RecordParser
class.
== Json Parser
You can easily parse JSON structures but that requires to provide the JSON content at once, but it
may not be convenient when you need to parse very large structures.
The non-blocking JSON parser is an event driven parser able to deal with very large structures.
It transforms a sequence of input buffer to a sequence of JSON parse events.
[source, $lang]
----
examples.ParseToolsExamples#jsonParserExample1()
----
The parser is non-blocking and emitted events are driven by the input buffers.
[source, $lang]
----
examples.ParseToolsExamples#jsonParserExample2
----
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:
[source, $lang]
----
examples.ParseToolsExamples#jsonParserExample3
----
The value mode can be set and unset during the parsing allowing you to switch between fine grained
events or JSON object value events.
[source, $lang]
----
examples.ParseToolsExamples#jsonParserExample4
----
You can do the same with arrays as well
[source, $lang]
----
examples.ParseToolsExamples#jsonParserExample5
----
You can also decode POJOs
[source, $lang]
----
examples.ParseToolsExamples#jsonParserExample6
----
Whenever the parser fails to process a buffer, an exception will be thrown unless you set an exception handler:
[source, $lang]
----
examples.ParseToolsExamples#jsonParserExample7
----
The parser also parses json streams:
- concatenated json streams: `{"temperature":30}{"temperature":50}`
- line delimited json streams: `{"an":"object"}\r\n3\r\n"a string"\r\nnull`
For more details, check out the JsonParser
class.Copyright © 2018 Eclipse. All rights reserved.