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 import org.slf4j.IMarkerFactory;
24 import org.slf4j.Marker;
25 import org.slf4j.MarkerFactory;
26
27 import java.io.IOException;
28
29 public class MarkerDeserializer extends StdDeserializer<Marker> {
30
31 IMarkerFactory markerFactory;
32
33 public MarkerDeserializer(IMarkerFactory markerFactory) {
34 this(null, markerFactory);
35 }
36
37 public MarkerDeserializer(Class<?> vc, IMarkerFactory markerFactory) {
38 super(vc);
39 this.markerFactory = markerFactory;
40 }
41
42 @Override
43 public Marker deserialize(JsonParser jp, DeserializationContext ctxt)
44 throws IOException, JsonProcessingException {
45 JsonNode node = jp.getCodec().readTree(jp);
46 String markerStr = node.asText();
47 Marker marker = markerFactory.getMarker(markerStr);
48 return marker;
49 }
50 }