Starting with Spring Framework 7.0, Spring adds support for Jackson 3, the next major generation of the Jackson JSON library. Jackson 3 requires Java 17+ and moves to an immutable, thread-safe JsonMapper design (replacing the mutable ObjectMapper used in Jackson 2), along with native JPMS module support and a new Maven groupId (tools.jackson) that lets Jackson 2 and Jackson 3 coexist on the same classpath without conflict. To take advantage of these improvements, Spring introduced a new message converter, JacksonJsonHttpMessageConverter, which is Jackson-3-aware and complements the existing Jackson-2-based MappingJackson2HttpMessageConverter (last tutorial).
Jackson 3 support is only available starting with Spring Framework 7.0 — it is not available in any earlier Spring version. At the same time, Spring's support for Jackson 2 (MappingJackson2HttpMessageConverter) is now deprecated as of Spring Framework 7.0, with removal currently planned for a future release (Spring Framework 7.2). This tutorial covers the new Jackson 3 based JSON conversion approach; see the earlier tutorial for the Jackson 2 based version, which remains supported for now but is on its way out.
Enabling Jackson 3 support in Spring MVC requires no explicit configuration — simply adding the tools.jackson.core:jackson-databind dependency to the classpath is enough. Spring MVC's auto-detection logic checks for the presence of Jackson 3's JsonMapper class at runtime and, if found, automatically registers JacksonJsonHttpMessageConverter as part of the default message converter list — the same auto-detection pattern Spring has always used for Jackson 2. No explicit converter registration or bean definition is needed unless you want to customize the JsonMapper configuration.
Example
Adding jackson 3 databind dependency
pom.xml<dependency>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>3.0.0</version>
</dependency>
Creating Backing Java Object
package com.logicbig.example;
import java.io.Serializable;
public class User implements Serializable {
private Long id;
private String name;
private String password;
private String emailAddress;
.............
}
The Controller
package com.logicbig.example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Controller
@RequestMapping("users")
public class UserController {
@Autowired
private UserService userService;
@RequestMapping(value = "register", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public void handleJsonPostRequest (@RequestBody User user, Model model) {
System.out.println("saving user: "+user);
userService.saveUser(user);
}
@RequestMapping(method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public List<User> handleAllUserRequest () {
return userService.getAllUsers();
}
}
Integration Test
package com.logicbig.example;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import org.springframework.test.web.servlet.assertj.MockMvcTester;
import org.springframework.web.context.WebApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;
@SpringJUnitWebConfig(MyWebConfig.class)
public class ControllerTest {
@Autowired
private WebApplicationContext wac;
private MockMvcTester mockMvcTester;
@org.junit.jupiter.api.BeforeEach
public void setup() {
this.mockMvcTester = MockMvcTester.from(this.wac);
}
@Test
public void testUserController() {
String userInJson = createUserInJson("joe",
"joe@example.com",
"abc");
assertThat(this.mockMvcTester.post().uri("/users/register")
.contentType(MediaType.APPLICATION_JSON)
.content(userInJson)
.exchange())
.hasStatus(CREATED);
String userInJson1 = createUserInJson("mike",
"mike@example.com",
"123");
assertThat(this.mockMvcTester.post()
.uri("/users/register")
.contentType(MediaType.APPLICATION_JSON)
.content(userInJson1)
.exchange())
.hasStatus(CREATED);
var getResult = this.mockMvcTester.get().uri("/users")
.accept(MediaType.APPLICATION_JSON)
.exchange();
assertThat(getResult)
.hasStatus(OK)
.bodyJson().extractingPath("$").asArray().hasSize(2);
assertThat(getResult).bodyJson().extractingPath("$[0].id")
.isEqualTo(1);
assertThat(getResult).bodyJson().extractingPath("$[0].name")
.isEqualTo("joe");
assertThat(getResult).bodyJson().extractingPath("$[0].emailAddress")
.isEqualTo("joe@example.com");
assertThat(getResult).bodyJson().extractingPath("$[0].password")
.isEqualTo("abc");
assertThat(getResult).bodyJson().extractingPath("$[1].id")
.isEqualTo(2);
assertThat(getResult).bodyJson().extractingPath("$[1].name")
.isEqualTo("mike");
assertThat(getResult).bodyJson().extractingPath("$[1].emailAddress")
.isEqualTo("mike@example.com");
assertThat(getResult).bodyJson().extractingPath("$[1].password")
.isEqualTo("123");
}
private static String createUserInJson(String name,
String email,
String password) {
return "{ \"name\": \"" + name + "\", " +
"\"emailAddress\":\"" + email + "\"," +
"\"password\":\"" + password + "\"}";
}
}
Output$ mvn test -Dtest=ControllerTest [INFO] Scanning for projects... [INFO] [INFO] ---------< com.logicbig.example:spring-json-jackson3-example >---------- [INFO] Building spring-json-jackson3-example 1.0-SNAPSHOT [INFO] from pom.xml [INFO] --------------------------------[ war ]--------------------------------- [INFO] [INFO] --- resources:3.3.1:resources (default-resources) @ spring-json-jackson3-example --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\example-projects\spring-mvc\spring-json-jackson3-example\src\main\resources [INFO] [INFO] --- compiler:3.15.0:compile (default-compile) @ spring-json-jackson3-example --- [INFO] Nothing to compile - all classes are up to date. [INFO] [INFO] --- resources:3.3.1:testResources (default-testResources) @ spring-json-jackson3-example --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\example-projects\spring-mvc\spring-json-jackson3-example\src\test\resources [INFO] [INFO] --- compiler:3.15.0:testCompile (default-testCompile) @ spring-json-jackson3-example --- [INFO] Nothing to compile - all classes are up to date. [INFO] [INFO] --- surefire:3.2.5:test (default-test) @ spring-json-jackson3-example --- [INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider [WARNING] file.encoding cannot be set as system property, use <argLine>-Dfile.encoding=...</argLine> instead [INFO] [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running com.logicbig.example.ControllerTest saving user: User{id=null, name='joe', password='abc', emailAddress='joe@example.com'} saving user: User{id=null, name='mike', password='123', emailAddress='mike@example.com'} [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.435 s -- in com.logicbig.example.ControllerTest [INFO] [INFO] Results: [INFO] [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 7.231 s [INFO] Finished at: 2026-07-19T16:20:42+08:00 [INFO] ------------------------------------------------------------------------
Example ProjectDependencies and Technologies Used: - spring-webmvc 7.0.6 (Spring Web MVC)
Version Compatibility: 7.0.0 - 7.0.6 Version compatibilities of spring-webmvc with this example: Versions in green have been tested.
- spring-test 7.0.6 (Spring TestContext Framework)
- jakarta.servlet-api 6.1.0 (Jakarta Servlet API documentation)
- junit-jupiter-engine 6.0.3 (Module "junit-jupiter-engine" of JUnit)
- jackson-databind 3.0.0 (General data-binding functionality for Jackson: works on core streaming API)
- hamcrest 3.0 (Core API and libraries of hamcrest matcher framework)
- assertj-core 3.26.3 (Rich and fluent assertions for testing in Java)
- json-path 2.10.0 (A library to query and verify JSON)
- JDK 25
- Maven 3.9.11
|
|