View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache license, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License. You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the license for the specific language governing permissions and
    15   * limitations under the license.
    16   */
    17  package org.apache.logging.log4j.core.jackson;
    18
    19  import org.apache.logging.log4j.Marker;
    20
    21  import com.fasterxml.jackson.annotation.JsonCreator;
    22  import com.fasterxml.jackson.annotation.JsonProperty;
    23  import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
    24  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
    25  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
    26
    27  /**
    28   * Jackson mix-in for {@link Marker}.
    29   * <p>
    30   * If we want to deal with more than one {@link Marker} implementation then recode these annotations to include metadata.
    31   * </p>
    32   * <p>
    33   * <em>Consider this class private.</em>
    34   * </p>
    35   * <p>
    36   * Example XML:
    37   * </p>
    38   * <pre>
    39  &lt;Marker name=&quot;Marker1&quot;&gt;
    40      &lt;Parents&gt;
    41          &lt;Marker name=&quot;ParentMarker1&quot;&gt;
    42              &lt;Parents&gt;
    43                  &lt;Marker name=&quot;GrandMotherMarker&quot;/&gt;
    44                  &lt;Marker name=&quot;GrandFatherMarker&quot;/&gt;
    45              &lt;/Parents&gt;
    46          &lt;/Marker&gt;
    47          &lt;Marker name=&quot;ParentMarker2&quot;/&gt;
    48      &lt;/Parents&gt;
    49  &lt;/Marker&gt;
    50   * </pre>
    51   *
    52   * @see Marker
    53   */
    54  // Alternate for multiple Marker implementation.
    55  // @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
    56  @JsonDeserialize(as = org.apache.logging.log4j.MarkerManager.Log4jMarker.class)
    57  abstract class MarkerMixIn implements Marker {
    58      private static final long serialVersionUID = 1L;
    59
    60      @JsonCreator
    61      MarkerMixIn(@JsonProperty("name") final String name) {
    62          // empty
    63      }
    64
    65      @Override
    66      @JsonProperty("name")
    67      @JacksonXmlProperty(isAttribute = true)
    68      public abstract String getName();
    69
    70      @Override
    71      @JsonProperty(JsonConstants.ELT_PARENTS)
    72      @JacksonXmlElementWrapper(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_PARENTS)
    73      @JacksonXmlProperty(namespace = XmlConstants.XML_NAMESPACE, localName = XmlConstants.ELT_MARKER)
    74      public abstract Marker[] getParents();
    75
    76  }