Skip to content

Commit b6da0d5

Browse files
committed
(bacport) Fix #4718: don't fail on serialization of DateTimeException (#4721)
1 parent 7693244 commit b6da0d5

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Diff for: release-notes/VERSION-2.x

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7-
2.18.0 (not yet released)
7+
2.17.3 (not yet released)
8+
9+
#4718: Should not fail on trying to serialize `java.time.DateTimeException`
810

911
2.17.2 (05-Jul-2024)
1012

Diff for: src/main/java/com/fasterxml/jackson/databind/util/BeanUtil.java

+4
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ public static String checkUnsupportedType(JavaType type) {
304304
if (className.indexOf('.', 10) >= 0) {
305305
return null;
306306
}
307+
// [databind#4718]: Also don't worry about Exception type(s)
308+
if (type.isTypeOrSubTypeOf(Throwable.class)) {
309+
return null;
310+
}
307311
typeName = "Java 8 date/time";
308312
moduleName = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310";
309313
} else if (isJodaTimeClass(className)) {

Diff for: src/test/java/com/fasterxml/jackson/databind/interop/DateJava8FallbacksTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.databind.interop;
22

3+
import java.time.DateTimeException;
34
import java.time.Instant;
45
import java.time.OffsetDateTime;
56
import java.time.ZoneId;
@@ -84,4 +85,19 @@ public void testAllowAsEmbedded() throws Exception
8485
}
8586
}
8687
}
88+
89+
// [databind#4718]: should not block serialization of `DateTimeException`
90+
@Test
91+
public void testAllowExceptionSer() throws Exception {
92+
String json = MAPPER.writeValueAsString(new DateTimeException("Test!"));
93+
assertTrue(MAPPER.readTree(json).isObject());
94+
}
95+
96+
// [databind#4718]: should not block deserialization of `DateTimeException`
97+
@Test
98+
public void testAllowExceptionDeser() throws Exception {
99+
DateTimeException exc = MAPPER.readValue("{\"message\":\"test!\"}",
100+
DateTimeException.class);
101+
assertNotNull(exc);
102+
}
87103
}

0 commit comments

Comments
 (0)