package com.alibaba.fastjson.parser.deserializer;

import java.io.Closeable;
import java.io.Serializable;
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 com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONToken;

public class JavaObjectDeserializer implements ObjectDeserializer {

    public final static JavaObjectDeserializer instance = new JavaObjectDeserializer();

    @SuppressWarnings("unchecked")
    public <T> 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<Object> list = new ArrayList<Object>();
            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();
            }

        }
        
        if (type instanceof Class
                && type != Object.class
                && type != Serializable.class
                && type != Cloneable.class
                && type != Closeable.class
                && type != Comparable.class) {
            return (T) parser.parseObject(type);    
        }

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

    public int getFastMatchToken() {
        return JSONToken.LBRACE;
    }
}

@@ -395,16 +395,60 @@
 ONToken;
+%0Aimport com.alibaba.fastjson.util.TypeUtils;
 %0A%0Apublic
@@ -1214,104 +1214,33 @@
 lass
-;%0A            if (componentType instanceof Class) %7B%0A                componentClass = (Class%3C?%3E) 
+ = TypeUtils.getRawClass(
 comp
@@ -1240,32 +1240,33 @@
 ss(componentType
+)
 ;%0A              
@@ -1263,20 +1263,16 @@
         
-  
-  
 Object%5B%5D
@@ -1351,20 +1351,16 @@
         
-    
 list.toA
@@ -1376,36 +1376,32 @@
 y);%0A            
-    
 return (T) array
@@ -1406,87 +1406,8 @@
 ay;%0A
-            %7D else %7B%0A                return (T) list.toArray();%0A            %7D%0A%0A
     

create raw class array instead of object array