First create a mapper :

import com.fasterxml.jackson.databind.ObjectMapper;// in play 2.3
ObjectMapper mapper = new ObjectMapper();

As Array:

MyClass[] myObjects = mapper.readValue(json, MyClass[].class);

As List:

List<MyClass> myObjects = mapper.readValue(jsonInput, new TypeReference<List<MyClass>>(){});

Another way to specify the List type:

List<MyClass> myObjects = mapper.readValue(jsonInput, mapper.getTypeFactory().constructCollectionType(List.class, MyClass.class));
Answer from Programmer Bruce on Stack Overflow
🌐
Mkyong
mkyong.com › home › java › how to parse json array with jackson
How to parse JSON Array with Jackson | mkyong.com
April 23, 2024 - package com.mkyong.json.jackson; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.mkyong.json.model.Person; import java.util.Arrays; import java.util.List; public class JsonArrayToObjectExample2 { public static void main(String[] args) throws JsonProcessingException { List<Person> list = Arrays.asList( new Person("mkyong", 42), new Person("ah pig", 20) ); ObjectMapper mapper = new ObjectMapper(); String result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(list); System.out.println(result); } } Output · [ { "name" : "mkyong", "age" : 42 }, { "name" : "ah pig", "age" : 20 } ] This example converts a list of Person objects to a JSON string with the list labeled as "Person": JsonArrayToObjectExample3.java ·
Discussions

data binding - Java convert to a list of objects from JSON - Stack Overflow
When converting the JSON to JAVA, how do I convert the object to a List, instead of a List? The LinkedHashMap keys are the name of the QuoteDTO member variables. ... Try this. This should do the work · ObjectMapper mapper = new ObjectMapper(); List ... More on stackoverflow.com
🌐 stackoverflow.com
Java - Object Mapper - JSON Array of Number to List<Long> - Stack Overflow
Consider also that in this way ... using ObjectMapper would force you to update also your endpoint in an important way. It's better and safer to separate payload representation from control logic. ... Sign up to request clarification or add additional context in comments. ... Sounds like a sane approach. 2018-10-11T13:33:08.317Z+00:00 ... I think that this is the best ideia. Worked for me, thank you 2018-10-11T17:47:27.853Z+00:00 ... If you just want your mapper to read into a List, use ... More on stackoverflow.com
🌐 stackoverflow.com
How to parse Json array with 2 or more different types using Jackson?

http://www.baeldung.com/jackson-inheritance

You'll need to have those types inherit from one base class though.

Also; that is really bad JSON.

More on reddit.com
🌐 r/javahelp
11
4
January 15, 2018
Deserialize list of array failed with enableDefaultTyping
I use the same ObjectMapper instance to serialize and deserialize List , deserialization failed with all of DefaultTyping's, and same as List , tested with the la... More on github.com
🌐 github.com
8
July 23, 2018
🌐
Baeldung
baeldung.com › home › json › jackson › jackson – unmarshall to collection/array
Jackson - Unmarshall to Collection/Array | Baeldung
April 26, 2024 - @Test public void givenJsonArray_whenDeserializingAsArray_thenCorrect() throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); List<MyDto> listOfDtos = Lists.newArrayList( new MyDto("a", 1, true), new MyDto("bc", 3, false)); String jsonArray = mapper.writeValueAsString(listOfDtos); // [{"stringValue":"a","intValue":1,"booleanValue":true}, // {"stringValue":"bc","intValue":3,"booleanValue":false}] MyDto[] asArray = mapper.readValue(jsonArray, MyDto[].class); assertThat(asArray[0], instanceOf(MyDto.class)); }
🌐
Makeinjava
makeinjava.com › home › convert list of objects to/from json in java (jackson objectmapper/ example)
Convert list of objects to/from JSON in java (jackson objectmapper/example)
January 1, 2024 - Convert JSON String to List of Person objects in java. package org.learn; import java.io.IOException; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; public class JSONListConverter { public static void main( String[] args ) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); //Set pretty printing of json objectMapper.enable(SerializationFeature.INDENT_OUTPUT); //Define map which will be converted to JSON List<Person> personList = Stream.of( new Person("Mike", "harvey", 34), new Person("Nick", "young", 75), new Person("Jack", "slater", 21 ), new Person("gary", "hudson", 55)) .collect(Collectors.toList()); //1.
🌐
Jenkov
jenkov.com › tutorials › java-json › jackson-objectmapper.html
Jackson ObjectMapper
Reading arrays of objects also works with other JSON sources than a string. For instance, a file, URL, InputStream, Reader etc. The Jackson ObjectMapper can also read a Java List of objects from a JSON array string.
🌐
Spring Framework Guru
springframework.guru › home › how to the jackson object mapper with json
How to The Jackson Object Mapper with JSON - Spring Framework Guru
October 22, 2024 - Using the objectMapper, we can also easily consume JSON arrays to Lists of POJOs. The following example will read a JSON array of Person objects and read it into a list of people.
Find elsewhere
🌐
Apps Developer Blog
appsdeveloperblog.com › home › java › java json › convert json array to java list using jackson
Convert JSON Array to Java List using Jackson - Apps Developer Blog
March 22, 2024 - For example, if we want to convert a JSON array to a list of custom objects called “Person”, we can define the TypeReference as follows: TypeReference<List<Person>> typeReference = new TypeReference<List<Person>>() {}; Parse the JSON array using the ObjectMapper and the defined TypeReference.
🌐
W3Docs
w3docs.com › java
How to use Jackson to deserialise an array of objects
ObjectMapper mapper = new ObjectMapper(); TypeReference<List<User>> typeReference = new TypeReference<List<User>>() {}; List<User> users = mapper.readValue(jsonString, typeReference); This will create a List of User objects from the JSON array.
🌐
Stack Abuse
stackabuse.com › converting-json-array-to-a-java-array-or-list
Convert JSON Array to a Java Array or List with Jackson
September 8, 2020 - Since we're mapping to an array of Language, we'll also specify this in the readValue() method: // It's advised to use ObjectMapper as a singleton and reuse the instance final ObjectMapper objectMapper = new ObjectMapper(); Language[] langs = objectMapper.readValue(json, Language[].class); Alternatively, you can extract the values directly into a list, using Jackson's TypeReference:
🌐
Baeldung
baeldung.com › home › json › jackson › intro to the jackson objectmapper
Intro to the Jackson ObjectMapper | Baeldung
December 9, 2025 - Jackson is a solid and mature JSON serialization/deserialization library for Java. The ObjectMapper API provides a straightforward way to parse and generate JSON response objects with a lot of flexibility. Additionally, we prototyped the ObjectMapperBuilder class to create immutable instances of the ObjectMapper class.
🌐
Medium
medium.com › @jamokoy397 › jackson-magic-deserializing-non-existent-lists-into-empty-lists-java-objectmapper-300ede79fa04
Jackson Magic: Deserializing Non-Existent Lists into Empty Lists (Java, ObjectMapper) | by Jamokoy Lancey | Medium
October 21, 2024 - Jackson’s core functionality revolves around the ObjectMapper and the use of annotations. The ObjectMapper is the central class in Jackson. It acts as the bridge between Java objects and JSON.
🌐
Reddit
reddit.com › r/javahelp › how to parse json array with 2 or more different types using jackson?
r/javahelp on Reddit: How to parse Json array with 2 or more different types using Jackson?
January 15, 2018 -

Hi guys, I've been searching online and stackoverflow but can't seem to find an answer to this. Basically the API i'm calling returns a json array as the root object. The two objects inside this array are different types. I have defined two Java classes to represent these two types and I'm wanting to read the json and convert them into my java object with jackson. Seems like there isn't a way to do this??

simple example of my objects:

class Type1 {
  String name
}

class Type2 {
  long age
}

The json coming from the api looks like this:

[
 {
    "name" : "mickey"
  },
  {
    "age" : 100
  }
]

How can I tell jackson to read in this "tree" but convert it to some object that is holding these two?

EDIT Here is a reply I made to another comment:

Ok, it seems like nobody is understanding what I'm saying. For one, I don't have control of the api I'm calling. I get what I get and have to deal with it.

What that api returns is a json ARRAY as the ROOT object. There are two objects in that array. Those two objects are NOT the same types.

IF that array was holding objects of the same type, i could do this:

MyObjects[] myobjs = new Objectmapper().readValue("some json array here", MyObjects[].class);

But like I said, i can't do this. Because the array is not holding objects of the same type. It would be more akin to a tuple like in python.

🌐
Medium
medium.com › @salvipriya97 › objectmapper-and-its-methods-examples-in-java-4a4cab75cb6b
ObjectMapper and its methods examples in Java | by Priya Salvi | Medium
June 25, 2024 - import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; public class Main { public static void main(String[] args) { ObjectMapper objectMapper = new ObjectMapper(); try { ObjectNode personNode = objectMapper.createObjectNode(); personNode.put("name", "John"); personNode.put("age", 30); String json = objectMapper.writeTreeAsString(personNode); System.out.println(json); // Output: {"name":"John","age":30} } catch (Exception e) { e.printStackTrace(); } } } Purpose: Converts an object of one type to another.
🌐
GitHub
github.com › thephpleague › object-mapper
GitHub - thephpleague/object-mapper · GitHub
This library supports hydration and serialization of objects. ... By default, input is mapped by property name, and types need to match. By default, keys are mapped from snake_case input to camelCase properties. If you want to keep the key names you can use the KeyFormatterWithoutConversion. use League\ObjectMapper\ObjectMapperUsingReflection; $mapper = new ObjectMapperUsingReflection(); class ExampleCommand { public function __construct( public readonly string $name, public readonly int $birthYear, ) {} } $command = $mapper->hydrateObject( ExampleCommand::class, [ 'name' => 'de Jonge', 'birth_year' => 1987 ], ); $command->name === 'de Jonge'; $command->birthYear === 1987;
🌐
GitHub
github.com › FasterXML › jackson-databind › issues › 2095
Deserialize list of array failed with enableDefaultTyping · Issue #2095 · FasterXML/jackson-databind
July 23, 2018 - I use the same ObjectMapper instance to serialize and deserialize List<String[]>, deserialization failed with all of DefaultTyping's, and same as List<Integer[]>, tested with the latest version 2.9.6. ObjectMapper objectMapper = new ObjectMapper(); objectMapper = objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT, JsonTypeInfo.As.PROPERTY); List<String[]> list = new ArrayList<>(); list.add(new String[] { "test" }); String s = objectMapper.writeValueAsString(list); // [["[Ljava.lang.String;",["test"]]] List<String[]> list2 = objectMapper.readValue(s, new TypeReference<List<String[]>>() { }); System.out.println(Arrays.equals(list.get(0), list2.get(0)));
Author: FasterXML
🌐
Medium
medium.com › javaguides › jackson-objectmapper-the-complete-guide-7d199d288fdf
Jackson ObjectMapper: The Complete Guide | by Ramesh Fadatare | JavaGuides | Medium
February 28, 2025 - The ObjectMapper class is the main API to: ✅ Convert Java Objects to JSON (Serialization) ✅ Convert JSON to Java Objects (Deserialization) ✅ Customize JSON structure using annotations ✅ Handle collections (List, Map) and nested objects ✅ Stream large JSON data efficiently