<commit_before>/**
 * Copyright (C) 2015 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.fabric8.kubernetes.internal;

import java.io.IOException;
import java.util.*;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;

import com.fasterxml.jackson.databind.node.ObjectNode;
import io.fabric8.kubernetes.api.model.KubernetesList;
import io.fabric8.kubernetes.api.model.KubernetesResource;
import io.fabric8.kubernetes.api.KubernetesResourceMappingProvider;

public class KubernetesDeserializer extends JsonDeserializer<KubernetesResource> {

    private static final String KIND = "kind";
    private static final String API_VERSION = "apiVersion";
    private static final String KEY_SEPARATOR = "#";

    private static final Map<String, Class<? extends KubernetesResource>> MAP = new HashMap<>();
    private static final List<String> PACKAGES;

    static {
        //Use service loader to load extension types.
        for (KubernetesResourceMappingProvider provider : ServiceLoader.load(KubernetesResourceMappingProvider.class)) {
            for (Map.Entry<String, Class<? extends KubernetesResource>> entry : provider.getMappings().entrySet()) {
                String key = entry.getKey();
                Class<? extends KubernetesResource> value = entry.getValue();
                //If the model is shaded (which is as part of kubernetes-client uberjar) this is going to cause conflicts.
                //This is why we NEED TO filter out incompatible resources.
                if (KubernetesResource.class.isAssignableFrom(value)) {
                        MAP.put(key, value);
                }
            }
        }

        PACKAGES = new ArrayList<String>(){{
            add("io.fabric8.kubernetes.api.model.");
            add("io.fabric8.kubernetes.api.model.apiextensions.");
            add("io.fabric8.kubernetes.api.model.apps.");
            add("io.fabric8.kubernetes.api.model.authentication.");
            add("io.fabric8.kubernetes.api.model.authorization.");<commit_msg>Fix #1634: Make map backing KubernetesDeserializer thread-safe<commit_after>/**
 * Copyright (C) 2015 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.fabric8.kubernetes.internal;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;

import com.fasterxml.jackson.databind.node.ObjectNode;
import io.fabric8.kubernetes.api.model.KubernetesList;
import io.fabric8.kubernetes.api.model.KubernetesResource;
import io.fabric8.kubernetes.api.KubernetesResourceMappingProvider;

public class KubernetesDeserializer extends JsonDeserializer<KubernetesResource> {

    private static final String KIND = "kind";
    private static final String API_VERSION = "apiVersion";
    private static final String KEY_SEPARATOR = "#";

    private static final Map<String, Class<? extends KubernetesResource>> MAP = new ConcurrentHashMap<>();
    private static final List<String> PACKAGES;

    static {
        //Use service loader to load extension types.
        for (KubernetesResourceMappingProvider provider : ServiceLoader.load(KubernetesResourceMappingProvider.class)) {
            for (Map.Entry<String, Class<? extends KubernetesResource>> entry : provider.getMappings().entrySet()) {
                String key = entry.getKey();
                Class<? extends KubernetesResource> value = entry.getValue();
                //If the model is shaded (which is as part of kubernetes-client uberjar) this is going to cause conflicts.
                //This is why we NEED TO filter out incompatible resources.
                if (KubernetesResource.class.isAssignableFrom(value)) {
                        MAP.put(key, value);
                }
            }
        }

        PACKAGES = new ArrayList<String>(){{
            add("io.fabric8.kubernetes.api.model.");
            add("io.fabric8.kubernetes.api.model.apiextensions.");
            add("io.fabric8.kubernetes.api.model.apps.");
            add("io.fabric8.kubernetes.api.model.authentication.");
            add("io.fabric8.kubernetes.api.model.authorization.");
{'fraction_non_alphanumeric': 0.09553349875930521, 'fraction_numerical': 0.00673520028358738, 'mean_word_length': 3.337432744043044, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7326624', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1392, 'n_words': 433}