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));
Answer from Frederic Close 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 - ... <dependency> <groupId>com.... : "mkyong", "age" : 42 }, { "name" : "ah pig", "age" : 20 } ] Create a Person object that matches the JSON property name....
🌐
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 - Using Jackson's ObjectMapper class, it's easy to read values and map them to an object, or an array of objects. We just use the readValue() method, passing the JSON contents and the class we'd like to map to.
Discussions

java - how to convert JSONArray to List of Object using camel-jackson - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
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
How to convert JSON Array of Values to Java Object - Stack Overflow
I am trying to convert my below Json Array to a specific Java Object. More on stackoverflow.com
🌐 stackoverflow.com
March 30, 2022
How to convert JSON string into List of Java object? - Stack Overflow
I am using below code to convert it into List of Java object : - ObjectMapper mapper = new ObjectMapper(); StudentList studentList = mapper.readValue(jsonString, StudentList.class); ... public class StudentList { private List participantList = new ArrayList(); //getters and setters } ... Exception : com.fasterxml.jackson... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Baeldung
baeldung.com › home › json › jackson › convert json array to java list
Convert JSON Array to Java List | Baeldung
August 13, 2025 - Then, we use the readValue() method of the ObjectMapper object to convert the JSON array String to a List. Similar to the assertion discussed previously, finally, we compare a specific field from the String JSON array to the jacksonList ...
🌐
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()); } }
🌐
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 - If your JSON array is stored in a JSON file, you can still read and parse its content to a list of Java Objects, as shown below:
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":"hello@email.com","credits"
 * :"100","twitter_username":""},
 * {"username":"Goodbye","email":"goodbye@email.com"
 * ,"credits":"0","twitter_username":""},
 * {"username":"mlsilva","email":"mlsilva@email.com"
 * ,"credits":"524","twitter_username":""},
 * {"username":"fsouza","email":"fsouza@email.com"
 * ,"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();
 }
}
🌐
How to do in Java
howtodoinjava.com › home › convert json array to list in java: jackson, gson, org.json
Convert JSON Array to List in Java: Jackson, Gson, Org.json
2 weeks ago - The toList() method converts the array into plain Java objects, where each JSON object becomes a HashMap, so the key order of the original JSON is lost. All three libraries convert the array correctly, and they differ in how much they do for us.
🌐
javathinking
javathinking.com › blog › convert-json-array-to-java-list
Converting JSON Array to Java List: A Comprehensive Guide — javathinking.com
import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; import java.util.Arrays; public class JacksonConverter { private static final ObjectMapper objectMapper = new ObjectMapper(); // Convert JSON array string to List of Strings public static List<String> convertToStringList(String jsonArray) throws Exception { return objectMapper.readValue(jsonArray, objectMapper.getTypeFactory().constructCollectionType(List.class, String.class)); } // Convert JSON array to List of custom objects public static <T> List<T> convertToObjectList(String jsonArray, Class<T> clazz) throws Exception { return objectMapper.readValue(jsonArray, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)); } }
Find elsewhere
🌐
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
🌐
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 - Converting a JSON array to a list manually involves using Java Jackson’s ObjectMapper class and iterating through the JSON array elements.
🌐
javathinking
javathinking.com › blog › how-to-convert-json-string-into-list-of-java-object
How to Convert JSON String to List of Java Objects Using Jackson ObjectMapper: Step-by-Step Example with Student Class — javathinking.com
Jackson, a powerful and widely used JSON processing library for Java, simplifies this task with its `ObjectMapper` class. In this blog, we’ll focus on a common use case: converting a JSON array string into a `List` of custom Java objects (e.g., `List `). We’ll walk through the process ...
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
JSON array to List - Java Code Geeks
October 2, 2023 - The resulting ArrayList is then printed on the console, showing the converted elements. ... Jackson is a popular and efficient Java library for JSON processing. It provides a set of high-level mapping tools for converting JSON data to Java objects (deserialization) and Java objects to JSON data (serialization).
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-convert-json-array-object-to-java-object
How to Convert JSON Array Object to Java Object? - GeeksforGeeks
July 23, 2025 - The User class defines a POJO to map JSON data with name and age properties. Getters and setters are provided for Jackson to populate objects.
🌐
YouTube
youtube.com › watch
How to Convert a JSON Array to a List in Java Using Jackson - YouTube
This post explores how to easily convert a JSON array to a list of Java objects using the Jackson library, along with a structured example for clarity.---Thi...
Published: August 2, 2025
Views: 5
🌐
Stack Overflow
stackoverflow.com › questions › 71679304 › how-to-convert-json-array-of-values-to-java-object
How to convert JSON Array of Values to Java Object - Stack Overflow
March 30, 2022 - java · json · jackson-databind · Share · Improve this question · Follow · edited Mar 30, 2022 at 15:24 · asked Mar 30, 2022 at 14:38 · PotatoGod · 2511 silver badge55 bronze badges 7 · 1 · That is not a "json array". It's a list or array of some Dummy class, transformed to a String.
🌐
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 List of Person objects to JSON String arrayToJson = objectMapper.writeValueAsString(personList); System.out.println("1. Convert List of person objects to JSON :"); System.out.println(arrayToJson); //2. Convert JSON to List of Person objects //Define Custom Type reference for List<Person> ...
🌐
YouTube
youtube.com › phcodegyan videos
Parse JSON to Java Object,ArrayList & Array Using Jackson Library - YouTube
This video shows how to parse json into Java Object,ArrayList and Array.Jackson Library has been used to achieve the same.At 0:37 secs , it's Maven based jav...
Published: July 31, 2021
Views: 22K
🌐
HowToDoInJava
howtodoinjava.com › home › gson › gson – parse json array to java array or list
Gson - Parse JSON Array to Java Array or List
April 4, 2023 - Gson parses JSON arrays as members without difficulty if they are non-root objects. We can use the fromJson() method in the usual manner and it will parse the JSON array correctly to the required java array or list.