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

external.com.alibaba.fastjson.parser.JavaObjectDeserializer Maven / Gradle / Ivy

Go to download

ratel api,used for developer on ratel system,an extension for xposed framewrok,ratel api compatable with original xposed framework

There is a newer version: 1.0.5
Show newest version
package external.com.alibaba.fastjson.parser;

import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.List;

import external.com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;

class JavaObjectDeserializer implements ObjectDeserializer {

    public final static JavaObjectDeserializer instance = new JavaObjectDeserializer();

    @SuppressWarnings("unchecked")
    public  T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        if (type instanceof GenericArrayType) {
            Type componentType = ((GenericArrayType) type).getGenericComponentType();
            if (componentType instanceof TypeVariable) {
                TypeVariable componentVar = (TypeVariable) componentType;
                componentType = componentVar.getBounds()[0];
            }

            List list = new ArrayList();
            parser.parseArray(componentType, list);
            Class componentClass;
            if (componentType instanceof Class) {
                componentClass = (Class) componentType;

                Object[] array = (Object[]) Array.newInstance(componentClass, list.size());
                list.toArray(array);
                return (T) array;
            } else {
                return (T) list.toArray();
            }

        }

        return (T) parser.parse(fieldName);
    }
}