001    /*;
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements. See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache license, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License. You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the license for the specific language governing permissions and
015     * limitations under the license.
016     */
017    package org.apache.logging.log4j.core.jackson;
018    
019    import java.io.IOException;
020    import java.util.HashMap;
021    import java.util.List;
022    import java.util.Map;
023    
024    import com.fasterxml.jackson.core.JsonParser;
025    import com.fasterxml.jackson.core.JsonProcessingException;
026    import com.fasterxml.jackson.core.type.TypeReference;
027    import com.fasterxml.jackson.databind.DeserializationContext;
028    import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
029    
030    /**
031     * <p>
032     * <em>Consider this class private.</em>
033     * </p>
034     */
035    public class ListOfMapEntryDeserializer extends StdDeserializer<Map<String, String>> {
036    
037        private static final long serialVersionUID = 1L;
038    
039        ListOfMapEntryDeserializer() {
040            super(Map.class);
041        }
042    
043        @Override
044        public Map<String, String> deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException,
045                JsonProcessingException {
046            final List<MapEntry> list = jp.readValueAs(new TypeReference<List<MapEntry>>() {
047                // empty
048            });
049            final HashMap<String, String> map = new HashMap<String, String>(list.size());
050            for (final MapEntry mapEntry : list) {
051                map.put(mapEntry.getKey(), mapEntry.getValue());
052            }
053            return map;
054        }
055    }