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);
}
}
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
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: