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.Level;
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  
24  import java.io.IOException;
25  
26  public class LevelDeserializer extends StdDeserializer<Level> {
27  
28      public  LevelDeserializer() {
29          this(null);
30      }
31  
32      public  LevelDeserializer(Class<?> vc) {
33          super(vc);
34      }
35  
36      @Override
37      public Level deserialize(JsonParser jp, DeserializationContext ctxt)
38              throws IOException, JsonProcessingException {
39          JsonNode node = jp.getCodec().readTree(jp);
40          String levelStr = node.asText();
41          Level level = Level.toLevel(levelStr);
42          return level;
43      }
44  }