VOOZH about

URL: https://www.geeksforgeeks.org/java/deserialize-json-array-to-a-single-java-object-with-jackson/

⇱ Deserialize JSON Array to a Single Java Object with Jackson - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Deserialize JSON Array to a Single Java Object with Jackson

Last Updated : 23 Jul, 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 Creation

Project Structure:

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

👁 Project Structure

Step 2: Add Jackson Dependency to POM.xml

Now, we will add Jackson dependency to the XML file.

Step 3: Create the Java POJO Class

After adding dependencies to pom.xml file, now we will create the POJO class.

Course.java

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.

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:

👁 Output in Console

Note: readValue() method handles all the conversion between JSON and Java objects based on naming conventions.

Comment
Article Tags: