I finally got it:

ObjectMapper objectMapper = new ObjectMapper();
TypeFactory typeFactory = objectMapper.getTypeFactory();
List<SomeClass> someClassList = objectMapper.readValue(jsonString, typeFactory.constructCollectionType(List.class, SomeClass.class));
Answer from mmutilva 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.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.mkyong.json.model.Person; import java.util.List; public class JsonArrayToObjectExample { public static void main(String[] args) throws JsonProcessingException { String jsonArray = "[{\"name\":\"mkyong\", \"age\":42}, {\"name\":\"ah pig\", \"age\":20}]"; ObjectMapper mapper = new ObjectMapper(); // 1. convert JSON array to Array objects Person[] person1 = mapper.readValue(jsonArray, Person[].class); for (Person p : person1) { System.out.println(p); } // 2.
Discussions

java - How to use Jackson to deserialise an array of objects - Stack Overflow
The Jackson data binding documentation indicates that Jackson supports deserialising "Arrays of all supported types" but I can't figure out the exact syntax for this. For a single object I would do More on stackoverflow.com
๐ŸŒ stackoverflow.com
java jackson parse json array - Stack Overflow
I need help with parsing, I've tried to create a different kind of model classes, but no use, please help me out here. the json looks like this: [ [ 1518909300000, "0.08815700", "0. More on stackoverflow.com
๐ŸŒ stackoverflow.com
March 1, 2018
java - Retrieve a value from json array using jackson - Stack Overflow
Here, text is the json string. ... text = builder.toString(); ObjectMapper mapper = new ObjectMapper(); Map map = mapper.readValue(text, new TypeReference>() { }); List mainMap2 = (List) map.get("weather"); //for (Object item : mainMap2) { // System.out.println("itemResult" + item.toString()); //} int id = (int)((Map)mainMap2.get(0)).get("id"); System.out.println(id); ... In jackson... More on stackoverflow.com
๐ŸŒ stackoverflow.com
November 23, 2016
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
๐ŸŒ
Jenkov
jenkov.com โ€บ tutorials โ€บ java-json โ€บ jackson-objectmapper.html
Jackson ObjectMapper
The Jackson ObjectMapper can also read an array of objects from a JSON array string.
๐ŸŒ
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 - In this article, we've used Jackson to parse and map the values from a JSON String and file into a Java array and list. This is done via the readValue() method, by specifying the JSON contents (String or file) and by specifying the POJO we'd like to map to.
๐ŸŒ
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)); } Reading the same JSON Array into a Java Collection is a bit more difficult โ€“ by default, Jackson will not be able to get the full generic type information and will instead create a collection of LinkedHashMap instances:
Find elsewhere
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ how to parse json string with jackson
How to parse JSON string with Jackson | mkyong.com
April 23, 2024 - package com.mkyong.json.jackson; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; public class BasicJsonArrayExample { public static void main(String[] args) { try { // a simple JSON array String json = "[" + "{\"name\": \"mkyong\", \"age\": 20}," + "{\"name\": \"ah pig\", \"age\": 40}," + "{\"name\": \"ag dog\", \"age\": 30}" + "]"; // Jackson main object ObjectMapper mapper = new ObjectMapper(); // read the json strings and convert it into JsonNode JsonNode arrayNode = mapper.readTree(json); // is this a array?
๐ŸŒ
Attacomsian
attacomsian.com โ€บ blog โ€บ jackson-read-json-file
How to Read JSON from a file using Jackson
October 14, 2022 - try { // create object mapper instance ObjectMapper mapper = new ObjectMapper(); // convert a JSON string to a Book object Book book = mapper.readValue(Paths.get("book.json").toFile(), Book.class); // print book System.out.println(book); } catch (Exception ex) { ex.printStackTrace(); } The above code will output the following on the console: Book{title='Thinking in Java', isbn='978-0131872486', year=1998, authors=[Bruce Eckel]} Suppose we have the following JSON file called books.json that contains a JSON array:
๐ŸŒ
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.

๐ŸŒ
Candidjava
candidjava.com โ€บ json-tutorial โ€บ json-array-to-string-array-using-jackson-example
Json Array to String Array Using Jackson Example
January 10, 2020 - package com.JasonProjectDeomo.Jackson.JsonRead; import java.io.File; import java.io.IOException; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.SerializationConfig; import com.JasonProjectDeomo.bean.Person; public class JsonFileToJavaStringArray { public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true); // read from string variable Person person = mapper.readValue(new File("JacksonFile/dataOne.json"), Person.class); String jsonString = mapper.writeValueAsString(person); System.out.println(jsonString); } }
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-can-we-convert-a-json-array-to-a-list-using-jackson-in-java
How can we convert a JSON array to a list using Jackson in Java?
June 5, 2025 - import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; import java.io.IOException; import java.util.ArrayList; public class JsonArrayToList{ public static void main(String[] args) { String jsonArray = "[{"name":"John","age":30},{"name":"Jane","age":25}]"; ObjectMapper objectMapper = new ObjectMapper(); try { List<Person> personList = objectMapper.readValue(jsonArray, new TypeReference<List<Person>>(){}); for (Person person : personList) { System.out.println("Name: " + person.getName() + ", Age: " + person.getAge()); } }
๐ŸŒ
Reflectoring
reflectoring.io โ€บ jackson
All You Need To Know About JSON Parsing With Jackson
July 14, 2022 - ObjectMapper is the most commonly ... It lives in com.fasterxml.jackson.databind. The readValue() method is used to parse (deserialize) JSON from a String, Stream, or File into POJOs....
๐ŸŒ
Attacomsian
attacomsian.com โ€บ blog โ€บ jackson-convert-json-array-to-from-java-list
Convert JSON array to a list using Jackson in Java
November 6, 2022 - public class User { public String name; public String email; private String[] roles; private boolean admin; public User() { } public User(String name, String email, String[] roles, boolean admin) { this.name = name; this.email = email; this.roles = roles; this.admin = admin; } // getters and setters, toString() .... (omitted for brevity) } Now we can use the readValue() method from the ObjectMapper class to transform the above JSON array to a list of User objects, as shown below:
๐ŸŒ
Level Up Lunch
leveluplunch.com โ€บ java โ€บ examples โ€บ convert-json-array-to-arraylist-of-objects-jackson
Json array to ArrayList jackson | Level Up Lunch
April 5, 2014 - First we will create an ObjectMapper, a class that provides the ability to convert between java and json, to deserialize json to java ArrayList. Next calling ObjectMapper.readValue passing json and call a method that creates a collection of a specified NavItem type.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ json โ€บ jackson โ€บ intro to the jackson objectmapper
Intro to the Jackson ObjectMapper - JSON
December 9, 2025 - String jsonCarArray = "[{ \"color\" : \"Black\", \"type\" : \"BMW\" }, { \"color\" : \"Red\", \"type\" : \"FIAT\" }]"; ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY, true); Car[] cars = objectMapper.readValue(jsonCarArray, Car[].class); // print cars ... String jsonCarArray = "[{ \"color\" : \"Black\", \"type\" : \"BMW\" }, { \"color\" : \"Red\", \"type\" : \"FIAT\" }]"; ObjectMapper objectMapper = new ObjectMapper(); List<Car> listCar = objectMapper.readValue(jsonCarArray, new TypeReference<List<Car>>(){}); // print cars ยท More information about handling collections with Jackson is available here.
๐ŸŒ
Reddit
reddit.com โ€บ r/androiddev โ€บ jackson parsing json containing an array of objects and array of maps w/ dynamic keys
r/androiddev on Reddit: Jackson parsing JSON containing an array of objects and array of maps w/ dynamic keys
July 28, 2013 -

I have json like this:

{

"users":{
       "1234":{
             "firstname":"Joe",
             "lastname":"Smith"
       },
       "9876":{
             "firstname":"Bob",
             "lastname":"Anderson"
       }
},
"jobs":[
      {
          "id":"abc",
          "location":"store"
      },
      {
          "id":"def",
          "location":"factory"
      }
]

}

I'm parsing this using Jackson and so I have been parsing responses using: readvalue(json, MyCustomClass.class)

Where MyCustomClass looks like

public class MyCustomClass{
      @JsonProperty("jobs")
      ArrayList<Job> jobs;
      
      @JsonProperty("users")
      ArrayList<UserMap> usersMap;
}

Now the jobs parse perfectly into Jobs objects but I can't get the users to parse since they have dynamic keys. I read about JsonAnyGetter/Setter and I tried making the UserMap object map that maps a string -> User like:

public class UserMap {

private HashMap<String,User> usersMap;


@JsonAnySetter
public void add(String key, User user){
	usersMap.put(key, user);
}

@JsonAnyGetter
public Map<String, User> getUsersMap(){
	return usersMap;
}


}

but that doesn't work. I think I can do it with a TypeReference wrapper but I only can think of a way to do that if that maps were the only type I was getting back. Since I am getting different types back (users and jobs) is it possible to do this?

๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 68435655 โ€บ parse-a-json-string-to-an-array-using-jackson
java - Parse a JSON string to an array using Jackson - Stack Overflow
So you have a list of JSON objects ( in the question this list contains only one element) and you have defined Data class that can map this single json object, right? In this case this question is actually about how to parse a list of object with jackson: ... import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; ... String str = "..."; List<Data> dataList = objectMapper.readValue(str, new TypeReference<List<Data>>(){});
๐ŸŒ
Quora
quora.com โ€บ How-can-I-parse-String-to-JSON-using-Jackson
How to parse String to JSON using Jackson - Quora
Answer (1 of 2): Assuming your json string represents a student as this : [code]{ "name": "Student 1", "age": 19, "scores": [10.0, 11.1, 12.2] } [/code]You can use Jacksonโ€™s ObjectMapper as this (assuming your json string is referenced by [code ]studentJson[/code]) : [code]final ObjectMapper...