Search in sources :

Example 1 with ThrowableDeserializer

use of com.alibaba.fastjson.parser.deserializer.ThrowableDeserializer in project uavstack by uavorg.

the class ParserConfig method getDeserializer.

public ObjectDeserializer getDeserializer(Class<?> clazz, Type type) {
    ObjectDeserializer derializer = derializers.get(type);
    if (derializer != null) {
        return derializer;
    }
    if (type == null) {
        type = clazz;
    }
    derializer = derializers.get(type);
    if (derializer != null) {
        return derializer;
    }
    {
        JSONType annotation = clazz.getAnnotation(JSONType.class);
        if (annotation != null) {
            Class<?> mappingTo = annotation.mappingTo();
            if (mappingTo != Void.class) {
                return getDeserializer(mappingTo, mappingTo);
            }
        }
    }
    if (type instanceof WildcardType || type instanceof TypeVariable || type instanceof ParameterizedType) {
        derializer = derializers.get(clazz);
    }
    if (derializer != null) {
        return derializer;
    }
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {
        for (AutowiredObjectDeserializer autowired : ServiceLoader.load(AutowiredObjectDeserializer.class, classLoader)) {
            for (Type forType : autowired.getAutowiredFor()) {
                derializers.put(forType, autowired);
            }
        }
    } catch (Exception ex) {
    // skip
    }
    derializer = derializers.get(type);
    if (derializer != null) {
        return derializer;
    }
    if (clazz.isEnum()) {
        derializer = new EnumDeserializer(clazz);
    } else if (clazz.isArray()) {
        derializer = ArrayDeserializer.instance;
    } else if (clazz == Set.class || clazz == HashSet.class || clazz == Collection.class || clazz == List.class || clazz == ArrayList.class) {
        derializer = CollectionDeserializer.instance;
    } else if (Collection.class.isAssignableFrom(clazz)) {
        derializer = CollectionDeserializer.instance;
    } else if (Map.class.isAssignableFrom(clazz)) {
        derializer = MapDeserializer.instance;
    } else if (Throwable.class.isAssignableFrom(clazz)) {
        derializer = new ThrowableDeserializer(this, clazz);
    } else {
        derializer = createJavaBeanDeserializer(clazz, type);
    }
    putDeserializer(type, derializer);
    return derializer;
}
Also used : ThrowableDeserializer(com.alibaba.fastjson.parser.deserializer.ThrowableDeserializer) ArrayList(java.util.ArrayList) JSONException(com.alibaba.fastjson.JSONException) ASMException(com.alibaba.fastjson.asm.ASMException) AccessControlException(java.security.AccessControlException) ParameterizedType(java.lang.reflect.ParameterizedType) EnumDeserializer(com.alibaba.fastjson.parser.deserializer.EnumDeserializer) WildcardType(java.lang.reflect.WildcardType) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) JSONType(com.alibaba.fastjson.annotation.JSONType) AutowiredObjectDeserializer(com.alibaba.fastjson.parser.deserializer.AutowiredObjectDeserializer) TypeVariable(java.lang.reflect.TypeVariable) Collection(java.util.Collection) JSONType(com.alibaba.fastjson.annotation.JSONType) JSONObjectDeserializer(com.alibaba.fastjson.parser.deserializer.JSONObjectDeserializer) AutowiredObjectDeserializer(com.alibaba.fastjson.parser.deserializer.AutowiredObjectDeserializer) JavaObjectDeserializer(com.alibaba.fastjson.parser.deserializer.JavaObjectDeserializer) ObjectDeserializer(com.alibaba.fastjson.parser.deserializer.ObjectDeserializer)

Aggregations

JSONException (com.alibaba.fastjson.JSONException)1 JSONType (com.alibaba.fastjson.annotation.JSONType)1 ASMException (com.alibaba.fastjson.asm.ASMException)1 AutowiredObjectDeserializer (com.alibaba.fastjson.parser.deserializer.AutowiredObjectDeserializer)1 EnumDeserializer (com.alibaba.fastjson.parser.deserializer.EnumDeserializer)1 JSONObjectDeserializer (com.alibaba.fastjson.parser.deserializer.JSONObjectDeserializer)1 JavaObjectDeserializer (com.alibaba.fastjson.parser.deserializer.JavaObjectDeserializer)1 ObjectDeserializer (com.alibaba.fastjson.parser.deserializer.ObjectDeserializer)1 ThrowableDeserializer (com.alibaba.fastjson.parser.deserializer.ThrowableDeserializer)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 TypeVariable (java.lang.reflect.TypeVariable)1 WildcardType (java.lang.reflect.WildcardType)1 AccessControlException (java.security.AccessControlException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1