Skip to content

Commit ec9871b

Browse files
authored
fix: detect incompatible Jackson version at startup (#24009)
Vaadin requires Jackson 3.1+ but Spring Boot 4.0.3 and earlier ship Jackson 3.0 which has incompatible API changes. This caused a cryptic NoSuchMethodError at runtime. Adding an early check in VaadinService.init() surfaces a clear error message with remediation steps instead.
1 parent 482b350 commit ec9871b

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

flow-server/src/main/java/com/vaadin/flow/internal/JacksonUtils.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,40 @@ public static ObjectMapper getMapper() {
8585
return objectMapper;
8686
}
8787

88+
/**
89+
* Checks that the Jackson version on the classpath is compatible with this
90+
* version of Vaadin by verifying that expected API methods are available.
91+
*
92+
* @throws IllegalStateException
93+
* if the Jackson version is not compatible
94+
*/
95+
public static void checkJacksonCompatibility() {
96+
try {
97+
ObjectMapper.class.getMethod("treeToValue", JsonNode.class,
98+
Class.class);
99+
} catch (NoSuchMethodException e) {
100+
String jacksonVersion = "unknown";
101+
try {
102+
jacksonVersion = ObjectMapper.class.getPackage()
103+
.getImplementationVersion();
104+
} catch (Exception ignored) {
105+
// ignore, we'll report "unknown"
106+
}
107+
throw new IllegalStateException(
108+
"The Jackson version on the classpath (" + jacksonVersion
109+
+ ") is not compatible with this version of"
110+
+ " Vaadin. If you are using Spring Boot, make"
111+
+ " sure it is version 4.0.4 or newer (using"
112+
+ " Jackson 3.1). If you have a Jackson 3.0"
113+
+ " dependency, upgrade it to 3.1. If you have"
114+
+ " a Jackson 2 dependency, upgrade it to 2.21"
115+
+ " or later. In other cases, check"
116+
+ " https://github.com/vaadin/platform/"
117+
+ "releases/tag/25.1.0 for more details.",
118+
e);
119+
}
120+
}
121+
88122
/**
89123
* Create a new ObjectNode.
90124
*

flow-server/src/main/java/com/vaadin/flow/server/VaadinService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ protected VaadinService() {
231231
* if a problem occurs when creating the service
232232
*/
233233
public void init() throws ServiceException {
234+
JacksonUtils.checkJacksonCompatibility();
234235
doSetClassLoader();
235236
instantiator = createInstantiator();
236237

flow-server/src/test/java/com/vaadin/flow/internal/JacksonUtilsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import tools.jackson.databind.node.ObjectNode;
4141

4242
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
43+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4344
import static org.junit.jupiter.api.Assertions.assertEquals;
4445
import static org.junit.jupiter.api.Assertions.assertFalse;
4546
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -507,4 +508,9 @@ public void writeValue_nullReturnsNullNode() {
507508
assertEquals(mapper.nullNode(), result);
508509
}
509510

511+
@Test
512+
public void checkJacksonCompatibility_compatibleVersion_noException() {
513+
assertDoesNotThrow(JacksonUtils::checkJacksonCompatibility);
514+
}
515+
510516
}

0 commit comments

Comments
 (0)