Skip to content

Commit efad166

Browse files
authored
Add test (#4072)
1 parent c6522de commit efad166

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/std/ThrowableDeserializer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) t
156156

157157
// 23-Jan-2018, tatu: One concern would be `message`, but without any-setter or single-String-ctor
158158
// (or explicit constructor). We could just ignore it but for now, let it fail
159-
159+
// [databind#4071]: In case of "message", skip for default constructor
160+
if (PROP_NAME_MESSAGE.equalsIgnoreCase(propName)) {
161+
p.skipChildren();
162+
continue;
163+
}
160164
// Unknown: let's call handler method
161165
handleUnknownProperty(p, ctxt, throwable, propName);
162166
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.fasterxml.jackson.databind.exc;
2+
3+
import com.fasterxml.jackson.databind.BaseMapTest;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
6+
// [databind#4071]: Ignore "message" for custom exceptions with only default constructor
7+
public class CustomExceptionDeser4071Test extends BaseMapTest
8+
{
9+
static class CustomThrowable4071 extends Throwable { }
10+
11+
static class CustomRuntimeException4071 extends RuntimeException { }
12+
13+
static class CustomCheckedException4071 extends Exception { }
14+
15+
private final ObjectMapper MAPPER = newJsonMapper();
16+
17+
public void testCustomException() throws Exception
18+
{
19+
String exStr = MAPPER.writeValueAsString(new CustomThrowable4071());
20+
assertNotNull(MAPPER.readValue(exStr, CustomThrowable4071.class));
21+
}
22+
23+
public void testCustomRuntimeException() throws Exception
24+
{
25+
String exStr = MAPPER.writeValueAsString(new CustomRuntimeException4071());
26+
assertNotNull(MAPPER.readValue(exStr, CustomRuntimeException4071.class));
27+
}
28+
29+
public void testCustomCheckedException() throws Exception
30+
{
31+
String exStr = MAPPER.writeValueAsString(new CustomCheckedException4071());
32+
assertNotNull(MAPPER.readValue(exStr, CustomCheckedException4071.class));
33+
}
34+
35+
public void testDeserAsThrowable() throws Exception
36+
{
37+
_testDeserAsThrowable(MAPPER.writeValueAsString(new CustomRuntimeException4071()));
38+
_testDeserAsThrowable(MAPPER.writeValueAsString(new CustomCheckedException4071()));
39+
_testDeserAsThrowable(MAPPER.writeValueAsString(new CustomThrowable4071()));
40+
}
41+
42+
private void _testDeserAsThrowable(String exStr) throws Exception
43+
{
44+
assertNotNull(MAPPER.readValue(exStr, Throwable.class));
45+
}
46+
}

0 commit comments

Comments
 (0)