• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
ErrorObject()17         ErrorObject() {}
18 
ErrorObject(Throwable throwable)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.
testCustomStackTraceDeser()27     public void testCustomStackTraceDeser() throws Exception
28     {
29         ObjectMapper mapper = newJsonMapper();
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 }
40