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
๐ŸŒ
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.
Discussions

Java - Object Mapper - JSON Array of Number to List - 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. ... Sounds like a sane approach. ... I think that this is the best ideia. Worked for me, thank you ... If you just want your mapper to read into a List, use ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - how to convert JSONArray to List of Object using camel-jackson - Stack Overflow
I had similar json response coming from client. Created one main list class, and one POJO class. More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to convert JSON string into List of Java object? - Stack Overflow
Now I want to convert it into Java object and store it in List of java object. e.g. In Student object. I am using below code to convert it into List of Java object : - ObjectMapper mapper = new ObjectMapper(); StudentList studentList = mapper.readValue(jsonString, StudentList.class); 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
๐ŸŒ
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 - try { // JSON array String json ... // convert JSON array to Java List List<User> users = new ObjectMapper().readValue(json, new TypeReference<List<User>>() {}); // print list of users users.forEach(System.out::println); ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ 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?\\n
June 5, 2025 - Following is the code that provides an example of how to convert a JSON array to a list using Jackson in Java: 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 (Pe
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ json โ€บ jackson โ€บ jackson โ€“ unmarshall to collection/array
Jackson - Unmarshall to Collection/Array | Baeldung
April 26, 2024 - @Test public void givenJsonArray_whenDeserializingAsListWithTypeReferenceHelp_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); List<MyDto> asList = mapper.readValue( jsonArray, new TypeReference<List<MyDto>>() { }); assertThat(asList.get(0), instanceOf(MyDto.class)); }
Top answer
1 of 5
98

The problem is not in your code but in your json:

{"Compemployes":[{"id":1001,"name":"jhon"}, {"id":1002,"name":"jhon"}]}

this represents an object which contains a property Compemployes which is a list of Employee. In that case you should create that object like:

class EmployeList{
    private List<Employe> compemployes;
    (with getter an setter)
}

and to deserialize the json simply do:

EmployeList employeList = mapper.readValue(jsonString,EmployeList.class);

If your json should directly represent a list of employees it should look like:

[{"id":1001,"name":"jhon"}, {"id":1002,"name":"jhon"}]

Last remark:

List<Employee> list2 = mapper.readValue(jsonString, 
TypeFactory.collectionType(List.class, Employee.class));

TypeFactory.collectionType is deprecated you should now use something like:

List<Employee> list = mapper.readValue(jsonString,
TypeFactory.defaultInstance().constructCollectionType(List.class,  
   Employee.class));
2 of 5
1
/*
 It has been answered in http://stackoverflow.com/questions/15609306/convert-string-to-json-array/33292260#33292260
 * put string into file jsonFileArr.json
 * [{"username":"Hello","email":"[email protected]","credits"
 * :"100","twitter_username":""},
 * {"username":"Goodbye","email":"[email protected]"
 * ,"credits":"0","twitter_username":""},
 * {"username":"mlsilva","email":"[email protected]"
 * ,"credits":"524","twitter_username":""},
 * {"username":"fsouza","email":"[email protected]"
 * ,"credits":"1052","twitter_username":""}]
 */

public class TestaGsonLista {

public static void main(String[] args) {
Gson gson = new Gson();
 try {
    BufferedReader br = new BufferedReader(new FileReader(
            "C:\\Temp\\jsonFileArr.json"));
    JsonArray jsonArray = new JsonParser().parse(br).getAsJsonArray();
    for (int i = 0; i < jsonArray.size(); i++) {
        JsonElement str = jsonArray.get(i);
        Usuario obj = gson.fromJson(str, Usuario.class);
        //use the add method from the list and returns it.
        System.out.println(obj);
        System.out.println(str);
        System.out.println("-------");
    }
 } catch (IOException e) {
    e.printStackTrace();
 }
}
Find elsewhere
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ json โ€บ jackson โ€บ convert json array to java list
Convert JSON Array to Java List | Baeldung
August 13, 2025 - In this section, weโ€™ll discuss how to convert a JSON array to a List using Jackson: @Test public void whenUsingJacksonLibrary_thenCompareTwoProducts() throws JsonProcessingException { // The jsonArray is the same JSON array from the above example ObjectMapper objectMapper = new ObjectMapper(); TypeReference<List<Product>> jacksonTypeReference = new TypeReference<List<Product>>() {}; List<Product> jacksonList = objectMapper.readValue(jsonArray, jacksonTypeReference); Assert.assertEquals(1, jacksonList.get(0).getId()); Assert.assertEquals("Sweet and cold", jacksonList.get(0).getDescription()); Assert.assertEquals("Icecream", jacksonList.get(0).getName()); }
๐ŸŒ
Medium
medium.com โ€บ @salvipriya97 โ€บ how-to-convert-json-array-to-java-pojo-using-jackson-367ac93f7b15
How to convert JSON array to Java POJO using Jackson | by Priya Salvi | Medium
June 18, 2024 - Main Class to Convert JSON to List of Person Objects: import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; public class Main { public static void main(String[] args) { String jsonArray = "[{\"name\":\"John\", \"age\":30, \"address\":[{\"apartment\":\"A1\",\"street\":\"Main St\",\"pinCode\":\"12345\"}], \"unknownField\":\"value\"}, {\"name\":\"Alice\", \"age\":25, \"address\":[{\"apartment\":\"B2\",\"street\":\"Second St\",\"pinCode\":\"67890\"}]}]"; try { ObjectMapper objectMapper = new ObjectMapper(); List<Person> per
๐ŸŒ
CopyProgramming
copyprogramming.com โ€บ howto โ€บ java-objectmapper-json-to-list-of-objects
Jackson ObjectMapper JSON to List of Objects: Complete Guide with 2026 Best Practices
December 3, 2025 - However, if Jackson can't instantiate the collection (e.g., it's an interface or abstract class), it will fall back to ArrayList. For maximum compatibility, stick with common types like List, Set, and Collection which Jackson handles seamlessly. Jackson ObjectMapper remains the essential tool for JSON processing in Java applications through 2026 and beyond.
๐ŸŒ
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 - List<Language> langList = objectMapper.readValue(json, new TypeReference<List<Language>>(){}); Without using TypeReference<>, which is advised, you can convert the array into a list with any other approach at your disposal, such as: List<Language> langList = new ArrayList(Arrays.asList(langs)); ...
๐ŸŒ
Jenkov
jenkov.com โ€บ tutorials โ€บ java-json โ€บ jackson-objectmapper.html
Jackson ObjectMapper
February 1, 2024 - This parameter tells Jackson to read a List of Car objects. The Jackson ObjectMapper can also read a Java Map from a JSON string. This can be useful if you do not know ahead of time the exact JSON structure that you will be parsing. Usually you will be reading a JSON object into a Java Map.
๐ŸŒ
Reflectoring
reflectoring.io โ€บ jackson
All You Need To Know About JSON Parsing With Jackson
July 15, 2022 - An ObjectMapper is responsible for building a tree of JsonNode nodes. It is the most flexible approach as it allows us to traverse the node tree when the JSON document doesnโ€™t map well to a POJO.
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ how to parse json array with jackson
How to parse JSON Array with Jackson - Mkyong.com
April 23, 2024 - In Jackson, we can convert the JSON array to an Array or List. ... 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.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ json โ€บ jackson โ€บ intro to the jackson objectmapper
Intro to the Jackson ObjectMapper | Baeldung
December 9, 2025 - The simple readValue API of the ObjectMapper is a good entry point. We can use it to parse or deserialize JSON content into a Java object.
๐ŸŒ
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 - This demonstrates the basic workflow of Jackson in handling object-to-JSON conversions. Jackson excels in handling complex data structures, including nested objects, lists, and arrays. It seamlessly manages these structures during serialization and deserialization. Letโ€™s explore an example with nested objects and lists. java import com.fasterxml.jackson.databind.ObjectMapper; public class Address { private String street; private String city; // Constructor, getters, and setters omitted for brevity } public class User { private String name; private int age; private Address address; private Li
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ convert json array to list: gson, jackson and org.json
Convert JSON Array to List: Gson, Jackson and Org.json
September 25, 2023 - When we use Jackson to parse JSON data into Java objects or lists, we should know the target type when dealing with generic types like List<T> or Map<K, V>. The TypeReference class provides the necessary type information to Jackson at runtime when deserializing JSON data into generic types. List<Person> readPersonListFromJsonArray(String jsonArray) throws JsonProcessingException { //Use autowired bean in Spring / Spring Boot ObjectMapper objectMapper = new ObjectMapper(); TypeReference<List<Person>> jacksonTypeReference = new TypeReference<>() {}; List<Person> personList = objectMapper.readValue(jsonArray, jacksonTypeReference); return personList; } Gson, developed by Google, is also a widely used Java library for working with JSON data.
๐ŸŒ
Medium
medium.com โ€บ @vino7tech โ€บ handling-json-with-objectmapper-in-spring-boot-6fc7ff39088b
Handling JSON with ObjectMapper in Spring Boot | by Vinotech | Medium
October 23, 2024 - This guide explores how to use ObjectMapper in a Spring Boot application for converting Java objects to JSON and vice versa. It covers key use cases like customizing JSON field names, handling unknown properties, working with lists, and configuring ObjectMapper for special scenarios like date formats and pretty printing.