From the course: Java EE 8 Essential Training

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Streaming parser events

Streaming parser events - Java EE Tutorial

From the course: Java EE 8 Essential Training

Start my 1-month free trial

Streaming parser events

- [Instructor] The JSON Processing API features a parser as part of the Streaming API. The parser can be used to efficiently read JSON objects using a poll model. Let's take a look. We're going to be working with the JsonParser inside of our JmsConsumer. We still have some JAXB related code within the consumer, so I'm going to go ahead and clean up that code so we can focus on the JsonParser. So once we've cleaned things up, we can go ahead and create a parser, and we're going to do so within a try block. The JsonParser implements the AutoCloseable interface, so that once we're finished with the parser, we can be sure that the resources will be cleaned up. So once we create a JsonParser object, all we need to do is use the Json object and invoke its createParser method. The JsonParser method will accept a reader. So we're going to go ahead and use a StringReader, and we'll pass in the json that we receive from the Jms…

Contents