Javatpoint Logo
Javatpoint Logo

Deserialize to Collection/Array in Jackson

Deserializing the JSON Array to a Java Array or Collection is one of the most important tasks when we work with APIs in Java. We can easily deserialize the JSON Array into Java Array or Collection by using Jackson.

Let's understand how we can deserialize the JSON array into both the Java Array and the Collection one by one:

Deserialize JSON Array to Java Array

We can easily deserialize JSON Array into Java Array by using the readValue() method of the ObectMapper class. In the readValue() method, we pass two parameters, i.e., jsonString and Student[].class.

Let's take an example to understand how we can deserialize JSON Array into Java Array by using ObjectMapper class:

DeserializeJSONArrayToJavaArrayExample.java

Output:

Deserialize to Collection/Array in Jackson

Deserialize JSON Array to Collection

Just like Java Array, we can also deserialize JSON Array to Java Collection by using the readValue() method of the ObjectMapper class.

Let's take an example to understand how we can deserialize JSON Array into java Collection by using Jackson:

DeserializeJSONArrayToJavaCollectionExample.java

Output:

Deserialize to Collection/Array in Jackson





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