Skip to content

Commit 985a3f9

Browse files
committed
Fix #1794
1 parent a43d23d commit 985a3f9

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Project: jackson-databind
66
2.9.3 (not yet released)
77

88
#1604: Nested type arguments doesn't work with polymorphic types
9+
#1794: `StackTraceElementDeserializer` not working if field visibility changed
10+
(reported by dsingley@github)
911
#1799: Allow creation of custom sub-types of `NullNode`, `BooleanNode`, `MissingNode`
1012
#1804: `ValueInstantiator.canInstantiate()` ignores `canCreateUsingArrayDelegate()`
1113
(reported byb henryptung@github)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ public StackTraceElement deserialize(JsonParser p, DeserializationContext ctxt)
5050
moduleName = p.getText();
5151
} else if ("moduleVersion".equals(propName)) {
5252
moduleVersion = p.getText();
53+
} else if ("declaringClass".equals(propName)) {
54+
// 01-Nov-2017: [databind#1794] Not sure if we should but... let's prune it for now
55+
;
5356
} else {
5457
handleUnknownProperty(p, ctxt, _valueClass, propName);
5558
}
59+
p.skipChildren(); // just in case we might get structured values
5660
}
5761
return constructValue(ctxt, className, methodName, fileName, lineNumber,
5862
moduleName, moduleVersion, classLoaderName);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.fasterxml.jackson.databind.exc;
2+
3+
import com.fasterxml.jackson.annotation.*;
4+
import com.fasterxml.jackson.databind.*;
5+
6+
// for [databind#1794]
7+
public class StackTraceElementTest extends BaseMapTest
8+
{
9+
public static class ErrorObject {
10+
11+
public String throwable;
12+
public String message;
13+
14+
// @JsonDeserialize(contentUsing = StackTraceElementDeserializer.class)
15+
public StackTraceElement[] stackTrace;
16+
17+
ErrorObject() {}
18+
19+
public ErrorObject(Throwable throwable) {
20+
this.throwable = throwable.getClass().getName();
21+
message = throwable.getMessage();
22+
stackTrace = throwable.getStackTrace();
23+
}
24+
}
25+
26+
// for [databind#1794] where extra `declaringClass` is serialized from private field.
27+
public void testCustomStackTraceDeser() throws Exception
28+
{
29+
ObjectMapper mapper = newObjectMapper();
30+
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
31+
32+
String json = mapper
33+
.writerWithDefaultPrettyPrinter()
34+
.writeValueAsString(new ErrorObject(new Exception("exception message")));
35+
36+
ErrorObject result = mapper.readValue(json, ErrorObject.class);
37+
assertNotNull(result);
38+
}
39+
}

0 commit comments

Comments
 (0)