类com.alibaba.fastjson.util.ParameterizedTypeImpl源码实例Demo

下面列出了怎么用com.alibaba.fastjson.util.ParameterizedTypeImpl的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: uavstack   文件: TypeReference.java
private Type handlerParameterizedType(ParameterizedType type, Type[] actualTypeArguments, int actualIndex) {
    Class<?> thisClass = this.getClass();
    Type rawType = type.getRawType();
    Type[] argTypes = type.getActualTypeArguments();

    for(int i = 0; i < argTypes.length; ++i) {
        if (argTypes[i] instanceof TypeVariable && actualIndex < actualTypeArguments.length) {
            argTypes[i] = actualTypeArguments[actualIndex++];
        }

        // fix for openjdk and android env
        if (argTypes[i] instanceof GenericArrayType) {
            argTypes[i] = TypeUtils.checkPrimitiveArray(
                    (GenericArrayType) argTypes[i]);
        }

        // 如果有多层泛型且该泛型已经注明实现的情况下,判断该泛型下一层是否还有泛型
        if(argTypes[i] instanceof ParameterizedType) {
            return handlerParameterizedType((ParameterizedType) argTypes[i], actualTypeArguments, actualIndex);
        }
    }

    Type key = new ParameterizedTypeImpl(argTypes, thisClass, rawType);
    return key;
}
 
源代码2 项目: uavstack   文件: TypeReference.java
/**
 * @since 1.2.9
 * @param actualTypeArguments
 */
protected TypeReference(Type... actualTypeArguments){
    Class<?> thisClass = this.getClass();
    Type superClass = thisClass.getGenericSuperclass();

    ParameterizedType argType = (ParameterizedType) ((ParameterizedType) superClass).getActualTypeArguments()[0];
    Type rawType = argType.getRawType();
    Type[] argTypes = argType.getActualTypeArguments();

    int actualIndex = 0;
    for (int i = 0; i < argTypes.length; ++i) {
        if (argTypes[i] instanceof TypeVariable &&
                actualIndex < actualTypeArguments.length) {
            argTypes[i] = actualTypeArguments[actualIndex++];
        }
        // fix for openjdk and android env
        if (argTypes[i] instanceof GenericArrayType) {
            argTypes[i] = TypeUtils.checkPrimitiveArray(
                    (GenericArrayType) argTypes[i]);
        }

        // 如果有多层泛型且该泛型已经注明实现的情况下,判断该泛型下一层是否还有泛型
        if(argTypes[i] instanceof ParameterizedType) {
            argTypes[i] = handlerParameterizedType((ParameterizedType) argTypes[i], actualTypeArguments, actualIndex);
        }
    }

    Type key = new ParameterizedTypeImpl(argTypes, thisClass, rawType);
    Type cachedType = classTypeCache.get(key);
    if (cachedType == null) {
        classTypeCache.putIfAbsent(key, key);
        cachedType = classTypeCache.get(key);
    }

    type = cachedType;

}
 
源代码3 项目: spring-boot-cookbook   文件: Response.java
public static void main(String[] args) {
    String jsonText = "{\"data\":{\"id\":1,\"name\":\"张三\"}}";
    Response<User> response = JSON.parseObject(jsonText, new ParameterizedTypeImpl(new Class[]{User.class}, null, Response.class));
    /**
     * {"data":{"id":1,"name":"张三"}}
     */
    System.out.println(response);

    response = JSON.parseObject(jsonText, new TypeReference<Response<User>>() {
    });
    /**
     * {"data":{"id":1,"name":"张三"}}
     */
    System.out.println(response);
}
 
源代码4 项目: java-tool   文件: TypeReference.java
private static Type create(Type[] actualTypeArguments, Type rawType) {
    return new ParameterizedTypeImpl(actualTypeArguments, null, rawType);
}
 
源代码5 项目: DevUtils   文件: FastjsonUtils.java
/**
 * 获取 List Type
 * @param type Bean.class
 * @return List<Bean> Type
 */
public static Type getListType(final Type type) {
    return new ParameterizedTypeImpl(new Type[]{type}, null, List.class);
}
 
源代码6 项目: DevUtils   文件: FastjsonUtils.java
/**
 * 获取 Set Type
 * @param type Bean.class
 * @return Set<Bean> Type
 */
public static Type getSetType(final Type type) {
    return new ParameterizedTypeImpl(new Type[]{type}, null, Set.class);
}
 
源代码7 项目: DevUtils   文件: FastjsonUtils.java
/**
 * 获取 Map Type
 * @param keyType   Key.class
 * @param valueType Value.class
 * @return Map<Key, Value> Type
 */
public static Type getMapType(final Type keyType, final Type valueType) {
    return new ParameterizedTypeImpl(new Type[]{keyType, valueType}, null, Map.class);
}
 
源代码8 项目: DevUtils   文件: FastjsonUtils.java
/**
 * 获取 Type
 * @param rawType       raw type
 * @param typeArguments type arguments
 * @return Type
 */
public static Type getType(final Type rawType, final Type... typeArguments) {
    return new ParameterizedTypeImpl(typeArguments, null, rawType);
}
 
 类所在包
 同包方法