Skip to content

Unable to use JsonLineMapper with Jackson 2 #5330

Closed

Description

@edeweerd1A

Bug description
If an application is using the JsonLineMapper but is stuck with using Jackson 2.x, it will break.

Environment
Java 25, Spring Batch 6, H2 database

Steps to reproduce

  • Create a Java application that has spring-batch-infrastructure as a dependency, typically a spring batch application
  • Add a jackson-databind v2 dependency
  • Have a usage of the JsonLineMapper in the application
  • Execute the application
Exception in thread "main" java.lang.NoClassDefFoundError: tools/jackson/databind/json/JsonMapper
	at org.springframework.batch.infrastructure.item.file.mapping.JsonLineMapper.<init>(JsonLineMapper.java:51)
	at LineMapperUser.main(LineMapperUser.java:5)
Caused by: java.lang.ClassNotFoundException: tools.jackson.databind.json.JsonMapper
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:490)
	... 2 more

Reproducer project linked hereunder.

Expected behavior
As per the migration guide, a migration to Jackson 3 is recommended but should not be mandatory.

Minimal Complete Reproducible example
Reproducer project:

reproducer-json-line-mapper-vs-jackson-2.zip

Potentially related issue: #1207

Work around

There is a workaround by having a custom LineMapper like this:

import com.fasterxml.jackson.databind.ObjectMapper;

public class Jackson2JsonLineMapper implements LineMapper<Map<String, Object>> {
  private final ObjectMapper jsonMapper = new ObjectMapper();
  @Override
  @SuppressWarnings("unchecked")
  public Map<String, Object> mapLine(String line, int lineNumber) throws Exception {
    return this.jsonMapper.readValue(line, Map.class);
  }
}

Activity

  1. added
    status: waiting-for-triage
    on Mar 11, 2026
  2. changed the title [-]https://github.com/spring-projects/spring-batch/issues/1207[/-] [+]Unable to use JsonLineMapper with Jackson 2[/+] on Mar 17, 2026
  3. answndud commented on Mar 18, 2026

    @answndud

    I’d like to take a look at this issue. I plan to investigate a compatibility fix that keeps JsonLineMapper usable when only Jackson 2 is present, while preserving the Jackson 3 path and adding focused regression coverage.

  4. answndud commented on Mar 18, 2026

    @answndud

    I opened a PR with a proposed fix: #5351

  5. fmbenhassine commented on May 26, 2026

    @fmbenhassine
    Contributor

    @edeweerd1A When I worked on the Jackson 3 upgrade for v6 (70865c1), I considered two options:

    Both options seemed inappropriate to me. So I upgraded the APIs to use Jackson 3 directly (ie no duplication, with one exception for Jackson2ExecutionContextStringSerializer that is kept in deprecated form). Therefore, if you want to use Jackson 2 with Spring Batch v6, you need a custom mapper as in your suggested workaround (you can get the Jackson 2 - compatible form from 70865c1). The migration guide is not accurate in that regard, so I will update it accordingly.

  6. added this to the 6.0.4 milestone on May 26, 2026
  7. fmbenhassine commented on May 28, 2026

    @fmbenhassine
    Contributor

    Migration guide updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions