Javatpoint Logo
Javatpoint Logo

Jackson Streaming API

Jackson Streaming API is a widely used APIs. It is used for reading and writing JSON data as a discrete event. The API provides JsonParser and JsonGenerator classes for reading and writing data simultaneously. Streaming API is the most powerful, fastest and lowest overhead approach for reading and writing JSON data. The concept of the token is used by this approach and handle each and every information of JSON carefully.

Let's take examples to understand how Streaming API is used for writing and reading JSON.

Creating JSON Using JsonGenerator Class

JsonGenerator is one of the most important class for writing JSON. It is very easy to use in our code. In order to use JsonGenerator class, first we create an instance of JsonGenerator class with the help of JsonFactory.createJsonGenerator(). We write the JSON value by using the write() method of the JsonGenerator class.

Syntax of using JsonGenerator class is as follows:

Let's create a program that demonstrate the same.

StreamingAPIExample1.java

Output:

Jackson Streaming API

Reading JSON Using JsonParser Class

JsonParser is another most important class that is used for reading JSON data. It is also very simple to use in our code. In order to use JsonParser class, first we create an instance of JsonParser with the help of JsonFactory.createJsonParser(). We read each JSON string as a token by using the nextToken() method.

Syntax of using JsonParser class is as follows:

Let's create a program that demonstrate the same.

StreamingAPIExample2.java

Output:

Jackson Streaming API





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA