1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ch.qos.logback.classic.jsonTest;
16
17 import ch.qos.logback.classic.spi.StackTraceElementProxy;
18 import com.fasterxml.jackson.core.JsonParser;
19 import com.fasterxml.jackson.core.JsonProcessingException;
20 import com.fasterxml.jackson.databind.DeserializationContext;
21 import com.fasterxml.jackson.databind.JsonNode;
22 import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
23 import com.fasterxml.jackson.databind.node.IntNode;
24
25 import java.io.IOException;
26
27 public class STEPDeserializer extends StdDeserializer<StackTraceElementProxy> {
28
29 public STEPDeserializer() {
30 this(null);
31 }
32
33 public STEPDeserializer(Class<?> vc) {
34 super(vc);
35 }
36
37 @Override
38 public StackTraceElementProxy deserialize(JsonParser jp, DeserializationContext ctxt)
39 throws IOException, JsonProcessingException {
40 JsonNode node = jp.getCodec().readTree(jp);
41 return jsonNodeToSTEP(node);
42 }
43
44 public static StackTraceElementProxy jsonNodeToSTEP(JsonNode node) {
45 String className = node.get("className").asText();
46 String methodName = node.get("methodName").asText();
47 String fileName = node.get("fileName").asText();
48
49 int lineNumber = (Integer) ((IntNode) node.get("lineNumber")).numberValue();
50
51 StackTraceElement ste = new StackTraceElement(className, methodName, fileName, lineNumber);
52 return new StackTraceElementProxy(ste);
53 }
54 }