Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Overview

In this short tutorial, we’ll shed light on how to fix the exception JsonMappingException: Can not deserialize instance of java.util.ArrayList from Object value (token `JsonToken.START_OBJECT`).

First, we’ll highlight the main cause of the exception. Then we’ll demonstrate how to reproduce it in practice, and finally, how to solve it.

2. Understanding the Exception

Typically, Jackson throws JsonMappingException to signal a fatal mapping error when deserializing a JSON string. Therefore, the stack trace “Can not deserialize instance of java.util.ArrayList” indicates that Jackson failed to map a JSON property into an instance of ArrayList.

In short, the most common cause of this exception is using curly braces “{…}” to denote a collection instead of brackets “[…]”.

3. Reproducing the Exception

Now that we know what causes Jackson to throw JsonMappingException, let’s see how to reproduce it using a practical example.

Let’s consider the Country class:

public class Country {

    private String name;
    private List<String> cities;

    // standard getters and setters
}

As we can see, a country is defined by a name and a list of cities.

Next, let’s pretend to use curly braces to define cities in a JSON string:

{
    "name": "Netherlands", 
    "cities": {"Amsterdam", "Tamassint"}
}

Now trying to deserialize the JSON string into an object of Country type will result in the following:

Cannot deserialize value of type `java.util.ArrayList<java.lang.String>` from Object value (token `JsonToken.START_OBJECT`)
at [Source: (String)"{"name":"Netherlands","cities":{"Amsterdam", "Tamassint"}}"; line: 1, column: 32] 
(through reference chain: com.baeldung.mappingexception.Country["cities"])
...

Finally, we’ll create a test case to confirm this:

@Test
public final void givenJsonWithInvalidList_whenDeserializing_thenThrowException() throws JsonParseException, IOException {
    String json = "{\"name\":\"Netherlands\",\"cities\":{\"Amsterdam\", \"Tamassint\"}}";
    ObjectMapper mapper = new ObjectMapper();

    Exception exception = assertThrows(JsonMappingException.class, () -> mapper.reader()
      .forType(Country.class)
      .readValue(json));

    assertTrue(exception.getMessage()
      .contains("Cannot deserialize value of type `java.util.ArrayList<java.lang.String>`"));
}

As shown above, Jackson fails with “Cannot deserialize value of type `java.util.ArrayList<java.lang.String>`”. 

The main reason here is that we used curly braces to represent a list of cities. For Jackson, {“Amsterdam”, “Tamassint”} isn’t a JSON array.

4. Fixing the Exception

The easiest way to avoid the exception is to use brackets instead of curly braces to define a collection of elements. So to solve the exception, we need to fix our JSON string first:

{ 
    "name": "Netherlands",
    "cities": ["Amsterdam", "Tamassint"]
}

Now let’s verify that everything works as excepted using a test case:

@Test
public final void givenJsonWithValidList_whenDeserializing_thenCorrect() throws JsonParseException, IOException {
    String json = "{\"name\":\"Netherlands\",\"cities\":[\"Amsterdam\", \"Tamassint\"]}";
    ObjectMapper mapper = new ObjectMapper();

    Country country = mapper.reader()
      .forType(Country.class)
      .readValue(json);

    assertEquals("Netherlands", country.getName());
    assertEquals(Arrays.asList("Amsterdam", "Tamassint"), country.getCities());
}

As we can see, the new JSON string is successfully deserialized into a Country object.

5. Conclusion

In this brief article, we discussed the main cause of the JsonMappingException: Can not deserialize instance of java.util.ArrayList from Object value (token `JsonToken.START_OBJECT`). Then we showcased how to produce the exception, and how to solve it.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW