JavaObjectDeserializer.java 文件源码

java
阅读 54 收藏 0 点赞 0 评论 0

项目:GitHub 作者:
@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) {
        return (T) parser.parseObject(type);    
    }

    return (T) parser.parse(fieldName);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号