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