Deserialize JSON Array to a Single Java Object with Jackson
Last Updated :
28 Apr, 2025
In Java, Deserializing an array to an object means converting the Java Array into a Single Object this is mainly done when working with object serialization.
To deserialize an array to an object in Java, we typically use the Jackson library. Jackson unlocks diverse use cases, such as transforming API responses or manipulating structured data within an application.
Note: Deserializing a JSON array into a single Java object directly with Jackson isn't typically possible due to type erasure in Java.
Step-by-Step Implementation
Below are the steps and implementation of deserializing JSON array to a single Java object with Jackson.
Step 1: Create a Maven Project
- Open any preferred IDE and create a new Maven project. Here we are using IntelliJ IDEA, so, we can do this by selecting File -> New -> Project.. -> Maven and following the wizard.

Project Structure:
Below is the Structure of the Project that we have created.

Step 2: Add Jackson Dependency to POM.xml
Now, we will add Jackson dependency to the XML file.
XML
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>DeserializeArray</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.0</version> <!-- Use the latest version available -->
</dependency>
</dependencies>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Step 3: Create the Java POJO Class
After adding dependencies to pom.xml file, now we will create the POJO class.
Course.java
Java
package org.example;
// Class
public class Course
{
private int id;
private String courseName;
private long coursePrice;
public Course() {}
// Constructor
public Course(int id, String courseName,
long coursePrice)
{
this.id = id;
this.courseName = courseName;
this.coursePrice = coursePrice;
}
// generating getters and setters
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getCourseName()
{
return courseName;
}
public void setCourseName(String courseName)
{
this.courseName = courseName;
}
public long getCoursePrice()
{
return coursePrice;
}
public void setCoursePrice(long coursePrice)
{
this.coursePrice = coursePrice;
}
}
The Course class defines a POJO to map JSON data with id, courseName, and coursePrice properties. Getters and setters are provided for Jackson to populate objects.
Step 4: In the Main class add logic of Deserialization of Java Array to Java Object
After creating POJO class, we will add logic of Deserialization of Java Array to Java Object in the main class.
Java
package org.example;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Main
{
public static void main(String[] args)
{
// JSON data representing an array of Course objects
String json
= "[{\n"
+ " \"id\": 1,\n"
+ " \"courseName\": \"Introduction to Java\",\n"
+ " \"coursePrice\": 30000.99\n"
+ "}\n]";
// Creating an object of ObjectMapper
ObjectMapper mapper = new ObjectMapper();
try {
// Deserializing the JSON array into an array of
// Course objects
Course[] course
= mapper.readValue(json, Course[].class);
// Accessing the first element of the array to
// get a single Course object
Course courses = course[0];
System.out.println(courses.getId());
System.out.println(courses.getCourseName());
System.out.println(courses.getCoursePrice());
}
catch (Exception e) {
e.printStackTrace();
}
}
}
In this example, we use the readValue() method of the ObjectMapper class to deserialize the JSON array into an array of Person objects. Then, we can access the first element of the array to get a single Person object.
Output:

Note: readValue() method handles all the conversion between JSON and Java objects based on naming conventions.
Similar Reads
Conversion of JSON Object Array to Java POJO In this article, we will learn how to use the widely used Jackson JSON library to map an array of JSON items to a Java POJO class instance. PrerequisitesA basic understanding of Java programming.A JSON library for Java, such as Jackson, Gson, or org.json, depending on your preference.Implementation
3 min read
How to Convert JSON Array Object to Java Object? JSON arrays are useful for storing multiple values together that are related or part of the same set. For example, storing a list of items, user profiles, product catalog, etc. JSON arrays allow ordered access to the values using indices like in regular arrays in other languages (0 indexed). Convers
3 min read
How to Convert an ArrayList of Objects to a JSON Array in Java? In Java, an ArrayList is a resizable array implementation of the List interface. It implements the List interface and is the most commonly used implementation of List. In this article, we will learn how to convert an ArrayList of objects to a JSON array in Java. Steps to Convert an ArrayList of Obje
3 min read
How to Efficiently Serialize and Deserialize Arrays in Java? Serialization is the process of converting an object into a byte stream and deserialization is the process of reconstructing the object from that byte stream. When working with the Arrays in Java, efficiently Serializing and Deserializing them is essential for data storage and transfer. Serialize an
2 min read
How to Serialize and Deserialize a TreeMap in Java? In Java, serialization is implemented by using the Serializable Interface. The use of the TreeMap class is a simple way to serialize and deserialize the objects. It is a component of the Java Collections framework. For writing and reading objects, we will be using the ObjectOutputStream and ObjectIn
2 min read
How to Serialize and Deserialize a HashSet in Java? Serialization is the technique of converting an object's state into a byte stream. The main purpose of serialization is to save the state of an object so that it can be rebuilt later. In Java, a Serializable interface is used to mark classes as serializable. When a class implements the Serializable
3 min read
How to Convert a Vector of Objects into a JSON Array in Java? In Java, the conversion of data structures like Vector to JSON (JavaScript Object Notation) format is required especially while working with the APIs or data interchange between different systems. The conversion of the Vector of an Object to the JSON Array has various approaches that we will learn i
3 min read
How to Convert JSON Array to String Array in Java? JSON stands for JavaScript Object Notation. It is one of the widely used formats to exchange data by web applications. JSON arrays are almost the same as arrays in JavaScript. They can be understood as a collection of data (strings, numbers, booleans) in an indexed manner. Given a JSON array, we wil
3 min read
How to Convert an ArrayList into a JSON String in Java? In Java, an ArrayList is a resizable array implementation of the List interface. It implements the List interface and is the most commonly used implementation of List. In this article, we will learn how to convert an ArrayList into a JSON string in Java. Steps to convert an ArrayList into a JSON str
2 min read
How to Read and Write JSON Files in Java? JSON (JavaScript Object Notation) is simple but poweÂrful.. It helps the server and the client to share information. Applications like Java use special tools, or libraries, that reÂad JSON. In Java, some libraries make it easy to read and write JSON files. One popular library is Jackson.In this art
4 min read