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.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 }