View Javadoc
1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2023, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
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  }