Spring Boot learning path Level 3 This level · 9 of 9
Hard java spring

How would you upgrade a service to Spring Boot 4, and where does AI help?

The 30 second answer

I'd move to the latest Spring Boot 3.5 first and clear its deprecation warnings, then upgrade. Mechanical work like the Jackson 3 package rename and the removal of ListenableFuture I hand to deterministic OpenRewrite recipes, and I use AI for the leftovers and review every diff. Before and after, I run contract tests that compare the JSON on the wire. Then a canary rollout, and only after that do I adopt new features.

Could you say this in an interview?

Spring Boot 4 sits on Spring Framework 7 and Jackson 3, so it is really three upgrades at once. Interviewers ask this to see whether you can run a large, breaking change safely, not whether you remember every renamed class.

1. Start from the right baseline. The official migration guide says to upgrade to the latest 3.5.x version first, so you build against the newest dependencies and see the deprecation warnings that 4.0 turns into removals. Spring Boot 4 requires at least Java 17. Add spring-boot-properties-migrator for one release cycle: it reports renamed configuration properties at startup and temporarily maps them for you.

2. Know the big breaking changes.

  • Jackson 3. Group IDs and packages move from com.fasterxml.jackson to tools.jackson. The exception is jackson-annotations, which keeps com.fasterxml.jackson.annotation, so @JsonProperty imports do not change. In Jackson 3 ObjectMapper and JsonFactory are immutable, so code that mutates a shared mapper after creation has to move to a builder. Several Spring Boot classes were renamed too: Jackson2ObjectMapperBuilderCustomizer becomes JsonMapperBuilderCustomizer, and @JsonComponent and @JsonMixin got Jackson-specific names.
  • Spring Framework 7 removals. ListenableFuture is removed in favour of CompletableFuture, along with other long-deprecated APIs. Jackson 2.x support in the framework is deprecated.
  • Null safety. Spring's JSR 305-style nullness annotations are deprecated in favour of JSpecify, and the framework codebase is now annotated with JSpecify.
// Jackson 2 (Spring Boot 3): a mutable, shared mapper
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);

// Jackson 3 (Spring Boot 4): configure once, then the mapper is immutable
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.json.JsonMapper;

JsonMapper mapper = JsonMapper.builder()
        .enable(SerializationFeature.INDENT_OUTPUT)
        .build();

3. Split the work between recipes and AI. Most of the diff is mechanical: import rewrites, renamed types, property keys, dependency coordinates. OpenRewrite publishes Spring Boot 4 migration recipes that make these changes deterministically. The same input always gives the same output, and you can rerun them on every branch. [Opinion] I use an AI assistant for the long tail the recipes cannot decide: custom serializers, a mapper that is mutated in three places, a ListenableFuture callback chain that needs restructuring into CompletableFuture stages. I treat its output like a junior engineer's pull request. It goes through small commits, code review and the full test suite, never one giant generated diff.

4. Protect the wire contract. Other services do not care which Jackson version you load. They care about the JSON bytes. Jackson 3 changes several defaults, so before upgrading I capture golden files or contract tests for the main request and response DTOs and assert they are unchanged afterwards. If something differs and a consumer cannot follow yet, Spring Boot 4 offers spring.jackson.use-jackson2-defaults=true, which makes the auto-configured JsonMapper use defaults as close as possible to Jackson 2 under Spring Boot 3.x. The guide strongly recommends adopting Jackson 3 where possible. If a library truly needs Jackson 2, dependency management for Jackson 2 remains, a spring-boot-jackson2 module exists, and spring.http.converters.preferred-json-mapper still accepts jackson2, but that value is deprecated. Treat all of these as a temporary bridge with a removal date.

5. Roll out like any risky change. Run the same configuration in staging that you will run in production, because a compatibility flag set only in non-production means your tests did not exercise what ships. Then canary one instance, watch error rates, latency and deserialization failures, and roll forward gradually. Only after the upgrade is stable do I adopt new features, such as the core resilience annotations @Retryable and @ConcurrencyLimit or the first-class API versioning in Spring MVC and WebFlux. Each one goes in as its own change.

Alternate interview scenarios

"A downstream service still expects the old JSON shape. How do you upgrade without breaking it?"

Find out what actually differs with a contract test, not by guessing. If it is a default (dates, empty values, property order), set it explicitly on the builder or use spring.jackson.use-jackson2-defaults for the transition. Keep the same setting in every environment, and track its removal as a ticket with the consumer team.

"Your AI tool produced a two-thousand-line migration diff. Would you merge it?"

Not as one change. I would rerun the deterministic recipes separately so that part of the diff is reproducible, then review the AI-written remainder in small, themed commits backed by tests. A diff nobody can review is a risk, whoever wrote it.

"After the upgrade, deserialization of a polymorphic field fails."

Check how polymorphic types are enabled. Global default typing on open-ended types like Object has a long history of deserialization gadget vulnerabilities, so Jackson requires a PolymorphicTypeValidator with an explicit allow-list (introduced in Jackson 2.10). Prefer @JsonTypeInfo and @JsonSubTypes on a closed hierarchy, and allow-list base packages only where you must. This is a Jackson safeguard, not a Spring Framework 7 rule.

"Did Spring Boot 4 introduce virtual threads?"

No. Spring Boot 3.2 already supported them through spring.threads.virtual.enabled=true on Java 21. If someone credits a framework upgrade for virtual threads, ask which setting actually changed.

Sources (8)
  1. Spring Boot 4.0 Migration Guidegithub.com
  2. Spring Framework 7.0 Release Notesgithub.com
  3. Jackson: Migrating to Jackson 3github.com
  4. Spring Boot system requirementsdocs.spring.io
  5. OpenRewrite: Spring Boot 4 recipesdocs.openrewrite.org
  6. Spring Boot application properties: `spring.http.converters.preferred-json-mapper`docs.spring.io
  7. Jackson docs: Polymorphic deserializationgithub.com
  8. Spring Boot 3.2 Release Notes: virtual threadsgithub.com
Previous
Next