All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.fastjson2.adapter.jackson.databind.module.SimpleDeserializers Maven / Gradle / Ivy

There is a newer version: 2.0.26
Show newest version
package com.alibaba.fastjson2.adapter.jackson.databind.module;

import com.alibaba.fastjson2.adapter.jackson.databind.JsonDeserializer;
import com.alibaba.fastjson2.modules.ObjectReaderModule;
import com.alibaba.fastjson2.reader.ObjectReader;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;

public class SimpleDeserializers
        implements ObjectReaderModule {
    protected HashMap> classMappings;
    protected boolean hasEnumDeserializer;

    public  void addDeserializer(Class forClass, JsonDeserializer deser) {
        if (classMappings == null) {
            classMappings = new HashMap<>();
        }
        classMappings.put(forClass, deser);
        if (forClass == Enum.class) {
            hasEnumDeserializer = true;
        }
    }

    public ObjectReader getObjectReader(Type type) {
        JsonDeserializer deserializer = classMappings.get(type);
        if (deserializer == null) {
            if (type instanceof ParameterizedType) {
                Type rawType = ((ParameterizedType) type).getRawType();
                deserializer = classMappings.get(rawType);
            }
        }
        return deserializer;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy