Spring Boot 4 Switches Default JSON Library from Jackson 2 to Jackson 3 – What Changes to Expect
Spring Boot 4 upgrades its default JSON processor to Jackson 3, introducing new package names, immutable builders, ISO‑8601 date serialization, and removal of checked exceptions, while preserving annotation compatibility for a smooth migration.
Spring Boot 4 switches its default JSON library from Jackson 2 to Jackson 3. The dependency tree looks like:
spring-boot-starter-jackson (4.x)
├── tools.jackson.core:jackson-core:3.x ← core library
└── com.fasterxml.jackson.annotation:jackson-annotations:2.x ← annotationsBoth Jackson 2 and Jackson 3 artifacts appear because the Jackson team kept annotation packages unchanged to allow a gradual migration.
Key migration changes
1. Package name change
Core classes moved from com.fasterxml.jackson to tools.jackson. Example:
// Jackson 2
import com.fasterxml.jackson.databind.ObjectMapper;
// Jackson 3
import tools.jackson.databind.ObjectMapper;Only core APIs change packages; annotation classes remain under com.fasterxml.jackson.annotation.
2. ObjectMapper → JsonMapper
Jackson 2’s ObjectMapper is mutable and not thread‑safe after configuration:
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);Jackson 3 introduces an immutable builder pattern:
JsonMapper mapper = JsonMapper.builder()
.enable(SerializationFeature.INDENT_OUTPUT)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.build();After build() the configuration is locked, the instance can be safely shared, and it is thread‑safe.
3. Default date serialization
Jackson 2 serializes dates as timestamps, while Jackson 3 uses ISO‑8601 strings:
// Jackson 2
{"nowDate":1767588151648}
// Jackson 3
{"nowDate":"2026-01-05T02:02:31.648Z"}This may break tests or API contracts that expect timestamps. A temporary compatibility setting is:
spring:
jackson:
use-jackson2-defaults: true4. Checked exceptions removed
Jackson 2 throws checked IOException for parsing errors:
try {
objectMapper.readValue(json, MyClass.class);
} catch (IOException e) {
// handle
}Jackson 3 consolidates all errors under the unchecked JacksonException (a subclass of RuntimeException), allowing cleaner code:
jsonMapper.readValue(json, MyClass.class);Consequently, stream operations that previously failed with lambda expressions now work:
// Jackson 2 – lambda may crash
list.stream()
.map(o -> objectMapper.writeValueAsString(o))
.toList();
// Jackson 3 – works fine
list.stream()
.map(o -> jsonMapper.writeValueAsString(o))
.toList();These changes modernize JSON handling in Spring Boot 4, providing immutable, thread‑safe mappers, more developer‑friendly date formats, and a simplified exception model.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Su San Talks Tech
Su San, former staff at several leading tech companies, is a top creator on Juejin and a premium creator on CSDN, and runs the free coding practice site www.susan.net.cn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
