Java 类com.alibaba.fastjson.parser.deserializer.ObjectDeserializer 实例源码

项目:boohee_v5.6    文件:ParserConfig.java   
public ObjectDeserializer getDeserializer(Type type) {
    ObjectDeserializer derializer = (ObjectDeserializer) this.derializers.get(type);
    if (derializer != null) {
        return derializer;
    }
    if (type instanceof Class) {
        return getDeserializer((Class) type, type);
    }
    if (!(type instanceof ParameterizedType)) {
        return JavaObjectDeserializer.instance;
    }
    Type rawType = ((ParameterizedType) type).getRawType();
    if (rawType instanceof Class) {
        return getDeserializer((Class) rawType, type);
    }
    return getDeserializer(rawType);
}
项目:boohee_v5.6    文件:ASMUtils.java   
public static void parseArray(Collection collection, ObjectDeserializer deser, DefaultJSONParser parser, Type type, Object fieldName) {
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 8) {
        lexer.nextToken(16);
    }
    parser.accept(14, 14);
    int index = 0;
    while (true) {
        collection.add(deser.deserialze(parser, type, Integer.valueOf(index)));
        index++;
        if (lexer.token() == 16) {
            lexer.nextToken(14);
        } else {
            parser.accept(15, 16);
            return;
        }
    }
}
项目:uavstack    文件:ParserConfig.java   
public ObjectDeserializer getDeserializer(Type type) {
    ObjectDeserializer derializer = this.derializers.get(type);
    if (derializer != null) {
        return derializer;
    }

    if (type instanceof Class<?>) {
        return getDeserializer((Class<?>) type, type);
    }

    if (type instanceof ParameterizedType) {
        Type rawType = ((ParameterizedType) type).getRawType();
        if (rawType instanceof Class<?>) {
            return getDeserializer((Class<?>) rawType, type);
        } else {
            return getDeserializer(rawType);
        }
    }

    return JavaObjectDeserializer.instance;
}
项目:itmarry    文件:ParserConfig.java   
public ObjectDeserializer getDeserializer(Type type) {
    ObjectDeserializer derializer = this.derializers.get(type);
    if (derializer != null) {
        return derializer;
    }

    if (type instanceof Class<?>) {
        return getDeserializer((Class<?>) type, type);
    }

    if (type instanceof ParameterizedType) {
        Type rawType = ((ParameterizedType) type).getRawType();
        if (rawType instanceof Class<?>) {
            return getDeserializer((Class<?>) rawType, type);
        } else {
            return getDeserializer(rawType);
        }
    }

    return JavaObjectDeserializer.instance;
}
项目:android_http_demo    文件:ParserConfig.java   
public ObjectDeserializer getDeserializer(Type type) {
    ObjectDeserializer derializer = this.derializers.get(type);
    if (derializer != null) {
        return derializer;
    }

    if (type instanceof Class<?>) {
        return getDeserializer((Class<?>) type, type);
    }

    if (type instanceof ParameterizedType) {
        Type rawType = ((ParameterizedType) type).getRawType();
        if (rawType instanceof Class<?>) {
            return getDeserializer((Class<?>) rawType, type);
        } else {
            return getDeserializer(rawType);
        }
    }

    return this.defaultSerializer;
}
项目:AndroidNio    文件:ParserConfig.java   
public ObjectDeserializer getDeserializer(Type type) {
    ObjectDeserializer derializer = this.derializers.get(type);
    if (derializer != null) {
        return derializer;
    }

    if (type instanceof Class<?>) {
        return getDeserializer((Class<?>) type, type);
    }

    if (type instanceof ParameterizedType) {
        Type rawType = ((ParameterizedType) type).getRawType();
        if (rawType instanceof Class<?>) {
            return getDeserializer((Class<?>) rawType, type);
        } else {
            return getDeserializer(rawType);
        }
    }

    return this.defaultSerializer;
}
项目:GitHub    文件:AETest.java   
public void test_for_ae() throws Exception {
    ParserConfig.getGlobalInstance().putDeserializer(Area.class, new ObjectDeserializer() {
        public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
            JSONObject jsonObject = (JSONObject) parser.parse();
            String areaType;

            if (jsonObject.get("type") instanceof String) {
                areaType = (String) jsonObject.get("type");
            } else {
                return null;
            }
            if (Area.TYPE_FLOOR.equals(areaType)) {
                 return (T) JSON.toJavaObject(jsonObject, Floor.class);
            } else if (Area.TYPE_ITEM.equals(areaType)) {
                return (T) JSON.toJavaObject(jsonObject, Item.class);
            }

            return null;
        }

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


    Data data = JSON.parseObject(jsonData, Data.class);

    Item item = (Item) ((Floor)(data.areaList.get(0))).children.get(0);
}
项目:boohee_v5.6    文件:ParserConfig.java   
public Map<String, FieldDeserializer> getFieldDeserializers(Class<?> clazz) {
    ObjectDeserializer deserizer = getDeserializer((Type) clazz);
    if (deserizer instanceof JavaBeanDeserializer) {
        return ((JavaBeanDeserializer) deserizer).getFieldDeserializerMap();
    }
    if (deserizer instanceof ASMJavaBeanDeserializer) {
        return ((ASMJavaBeanDeserializer) deserizer).getInnterSerializer().getFieldDeserializerMap();
    }
    return Collections.emptyMap();
}
项目:uavstack    文件:ParserConfig.java   
public Map<String, FieldDeserializer> getFieldDeserializers(Class<?> clazz) {
    ObjectDeserializer deserizer = getDeserializer(clazz);

    if (deserizer instanceof JavaBeanDeserializer) {
        return ((JavaBeanDeserializer) deserizer).getFieldDeserializerMap();
    } else if (deserizer instanceof ASMJavaBeanDeserializer) {
        return ((ASMJavaBeanDeserializer) deserizer).getInnterSerializer().getFieldDeserializerMap();
    } else {
        return Collections.emptyMap();
    }
}
项目:uavstack    文件:ASMUtils.java   
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void parseArray(Collection collection, //
                              ObjectDeserializer deser, //
                              DefaultJSONParser parser, //
                              Type type, //
                              Object fieldName) {

    final JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.NULL) {
        lexer.nextToken(JSONToken.COMMA);
    }

    parser.accept(JSONToken.LBRACKET, JSONToken.LBRACKET);

    int index = 0;
    for (;;) {
        Object item = deser.deserialze(parser, type, index);
        collection.add(item);
        index++;
        if (lexer.token() == JSONToken.COMMA) {
            lexer.nextToken(JSONToken.LBRACKET);
        } else {
            break;
        }
    }
    parser.accept(JSONToken.RBRACKET, JSONToken.COMMA);
}
项目:itmarry    文件:ParserConfig.java   
public Map<String, FieldDeserializer> getFieldDeserializers(Class<?> clazz) {
    ObjectDeserializer deserizer = getDeserializer(clazz);

    if (deserizer instanceof JavaBeanDeserializer) {
        return ((JavaBeanDeserializer) deserizer).getFieldDeserializerMap();
    } else if (deserizer instanceof ASMJavaBeanDeserializer) {
        return ((ASMJavaBeanDeserializer) deserizer).getInnterSerializer().getFieldDeserializerMap();
    } else {
        return Collections.emptyMap();
    }
}
项目:itmarry    文件:ASMUtils.java   
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void parseArray(Collection collection, //
                              ObjectDeserializer deser, //
                              DefaultJSONParser parser, //
                              Type type, //
                              Object fieldName) {

    final JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.NULL) {
        lexer.nextToken(JSONToken.COMMA);
    }

    parser.accept(JSONToken.LBRACKET, JSONToken.LBRACKET);

    int index = 0;
    for (;;) {
        Object item = deser.deserialze(parser, type, index);
        collection.add(item);
        index++;
        if (lexer.token() == JSONToken.COMMA) {
            lexer.nextToken(JSONToken.LBRACKET);
        } else {
            break;
        }
    }
    parser.accept(JSONToken.RBRACKET, JSONToken.COMMA);
}
项目:android_http_demo    文件:ParserConfig.java   
public ObjectDeserializer createJavaBeanDeserializer(Class<?> clazz, Type type) {
    if (clazz == Class.class) {
        return this.defaultSerializer;
    }

    return new JavaBeanDeserializer(this, clazz, type);
}
项目:android_http_demo    文件:ParserConfig.java   
public Map<String, FieldDeserializer> getFieldDeserializers(Class<?> clazz) {
    ObjectDeserializer deserizer = getDeserializer(clazz);

    if (deserizer instanceof JavaBeanDeserializer) {
        return ((JavaBeanDeserializer) deserizer).getFieldDeserializerMap();
    } else {
        return Collections.emptyMap();
    }
}
项目:AndroidNio    文件:ParserConfig.java   
public ObjectDeserializer createJavaBeanDeserializer(Class<?> clazz, Type type) {
    if (clazz == Class.class) {
        return this.defaultSerializer;
    }

    return new JavaBeanDeserializer(this, clazz, type);
}
项目:AndroidNio    文件:ParserConfig.java   
public Map<String, FieldDeserializer> getFieldDeserializers(Class<?> clazz) {
    ObjectDeserializer deserizer = getDeserializer(clazz);

    if (deserizer instanceof JavaBeanDeserializer) {
        return ((JavaBeanDeserializer) deserizer).getFieldDeserializerMap();
    } else {
        return Collections.emptyMap();
    }
}
项目:GitHub    文件:AbstractSerializeTest.java   
protected void setUp() throws Exception {
    ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.AbstractSerializeTest");

    ObjectDeserializer serializerB = ParserConfig.getGlobalInstance().getDeserializer(B.class);
    ParserConfig.getGlobalInstance().putDeserializer(A.class, serializerB);
}
项目:GitHub    文件:Bug_for_issue_372.java   
public void test_for_issue() throws Exception {
    ParserConfig config = new ParserConfig();
    ObjectDeserializer deser = config.getDeserializer(Model.class);
    Assert.assertEquals(JavaBeanDeserializer.class, deser.getClass());
}
项目:boohee_v5.6    文件:ParserConfig.java   
public IdentityHashMap<Type, ObjectDeserializer> getDerializers() {
    return this.derializers;
}
项目:boohee_v5.6    文件:ParserConfig.java   
public ObjectDeserializer createJavaBeanDeserializer(Class<?> clazz, Type type) {
    boolean asmEnable = this.asmEnable;
    if (asmEnable) {
        Class<?> superClass = clazz;
        while (Modifier.isPublic(superClass.getModifiers())) {
            superClass = superClass.getSuperclass();
            if (superClass != Object.class) {
                if (superClass == null) {
                    break;
                }
            }
            break;
        }
        asmEnable = false;
    }
    if (clazz.getTypeParameters().length != 0) {
        asmEnable = false;
    }
    if (asmEnable && this.asmFactory != null && this.asmFactory.isExternalClass(clazz)) {
        asmEnable = false;
    }
    if (asmEnable) {
        asmEnable = ASMUtils.checkName(clazz.getName());
    }
    if (asmEnable) {
        if (clazz.isInterface()) {
            asmEnable = false;
        }
        DeserializeBeanInfo beanInfo = DeserializeBeanInfo.computeSetters(clazz, type);
        if (beanInfo.getFieldList().size() > 200) {
            asmEnable = false;
        }
        if (beanInfo.getDefaultConstructor() == null && !clazz.isInterface()) {
            asmEnable = false;
        }
        for (FieldInfo fieldInfo : beanInfo.getFieldList()) {
            if (fieldInfo.isGetOnly()) {
                asmEnable = false;
                break;
            }
            Class<?> fieldClass = fieldInfo.getFieldClass();
            if (!Modifier.isPublic(fieldClass.getModifiers())) {
                asmEnable = false;
                break;
            }
            if (fieldClass.isMemberClass() && !Modifier.isStatic(fieldClass.getModifiers())) {
                asmEnable = false;
            }
            if (!ASMUtils.checkName(fieldInfo.getMember().getName())) {
                asmEnable = false;
            }
        }
    }
    if (asmEnable && clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers())) {
        asmEnable = false;
    }
    if (!asmEnable) {
        return new JavaBeanDeserializer(this, clazz, type);
    }
    try {
        return this.asmFactory.createJavaBeanDeserializer(this, clazz, type);
    } catch (NoSuchMethodException e) {
        return new JavaBeanDeserializer(this, clazz, type);
    } catch (ASMException e2) {
        return new JavaBeanDeserializer(this, clazz, type);
    } catch (Exception e3) {
        throw new JSONException("create asm deserializer error, " + clazz.getName(), e3);
    }
}
项目:boohee_v5.6    文件:ParserConfig.java   
public void putDeserializer(Type type, ObjectDeserializer deserializer) {
    this.derializers.put(type, deserializer);
}
项目:boohee_v5.6    文件:ParserConfig.java   
public ObjectDeserializer getDeserializer(FieldInfo fieldInfo) {
    return getDeserializer(fieldInfo.getFieldClass(), fieldInfo.getFieldType());
}
项目:boohee_v5.6    文件:DefaultJSONParser.java   
public void parseArray(Type type, Collection array, Object fieldName) {
    if (this.lexer.token() == 21 || this.lexer.token() == 22) {
        this.lexer.nextToken();
    }
    if (this.lexer.token() != 14) {
        throw new JSONException("exepct '[', but " + JSONToken.name(this.lexer.token()));
    }
    ObjectDeserializer deserializer;
    if (Integer.TYPE == type) {
        deserializer = IntegerCodec.instance;
        this.lexer.nextToken(2);
    } else if (String.class == type) {
        deserializer = StringCodec.instance;
        this.lexer.nextToken(4);
    } else {
        deserializer = this.config.getDeserializer(type);
        this.lexer.nextToken(deserializer.getFastMatchToken());
    }
    ParseContext context = getContext();
    setContext(array, fieldName);
    int i = 0;
    while (true) {
        if (isEnabled(Feature.AllowArbitraryCommas)) {
            while (this.lexer.token() == 16) {
                this.lexer.nextToken();
            }
        }
        try {
            if (this.lexer.token() == 15) {
                break;
            }
            if (Integer.TYPE == type) {
                array.add(IntegerCodec.instance.deserialze(this, null, null));
            } else if (String.class == type) {
                String value;
                if (this.lexer.token() == 4) {
                    value = this.lexer.stringVal();
                    this.lexer.nextToken(16);
                } else {
                    Object obj = parse();
                    if (obj == null) {
                        value = null;
                    } else {
                        value = obj.toString();
                    }
                }
                array.add(value);
            } else {
                Object obj2;
                if (this.lexer.token() == 8) {
                    this.lexer.nextToken();
                    obj2 = null;
                } else {
                    obj2 = deserializer.deserialze(this, type, Integer.valueOf(i));
                }
                array.add(obj2);
                checkListResolve(array);
            }
            if (this.lexer.token() == 16) {
                this.lexer.nextToken(deserializer.getFastMatchToken());
            }
            i++;
        } finally {
            setContext(context);
        }
    }
    this.lexer.nextToken(16);
}
项目:uavstack    文件:ParserConfig.java   
public IdentityHashMap<Type, ObjectDeserializer> getDerializers() {
    return derializers;
}
项目:uavstack    文件:ParserConfig.java   
public void putDeserializer(Type type, ObjectDeserializer deserializer) {
    derializers.put(type, deserializer);
}
项目:uavstack    文件:ParserConfig.java   
public ObjectDeserializer getDeserializer(FieldInfo fieldInfo) {
    return getDeserializer(fieldInfo.getFieldClass(), fieldInfo.getFieldType());
}
项目:hsweb-framework    文件:HswebAutoConfiguration.java   
@Bean
@Primary
@ConfigurationProperties(prefix = "fastjson")
public FastJsonGenericHttpMessageConverter fastJsonGenericHttpMessageConverter(EntityFactory entityFactory) {
    JSON.DEFAULT_PARSER_FEATURE |= Feature.DisableFieldSmartMatch.getMask();
    FastJsonGenericHttpMessageConverter converter = new FastJsonGenericHttpMessageConverter();
    converter.setFeatures(
            SerializerFeature.WriteNullListAsEmpty,
            SerializerFeature.WriteNullNumberAsZero,
            SerializerFeature.WriteNullBooleanAsFalse
    );
    converter.setConverters(converters);
    ParserConfig.global = new ParserConfig() {
        @Override
        public ObjectDeserializer getDeserializer(Type type) {
            ObjectDeserializer derializer = getDeserializers().get(type);
            if (derializer != null) {
                return derializer;
            }
            if (type instanceof Class) {
                Class classType = ((Class) type);
                if (classType.isEnum()) {
                    return super.getDeserializer(type);
                }
                checkAutoType(type.getTypeName(), ((Class) type));
                if (Modifier.isAbstract(classType.getModifiers()) || Modifier.isInterface(classType.getModifiers())) {
                    Class realType;
                    if (entityFactory != null && (realType = entityFactory.getInstanceType(classType)) != null) {
                        return new JavaBeanDeserializer(this, realType, type);
                    }
                } else {
                    return new JavaBeanDeserializer(this, classType);
                }
            }

            return super.getDeserializer(type);
        }
    };

    //fastjson.parser.autoTypeAccept
    ParserConfig.global.addAccept("org.hswebframework.web.entity.");
    ParserConfig.global.addDeny("org.hswebframework.ezorm.core.param.SqlTerm");
    return converter;
}
项目:itmarry    文件:ParserConfig.java   
public IdentityHashMap<Type, ObjectDeserializer> getDerializers() {
    return derializers;
}
项目:itmarry    文件:ParserConfig.java   
public ObjectDeserializer createJavaBeanDeserializer(Class<?> clazz, Type type) {
    boolean asmEnable = this.asmEnable;
    if (asmEnable) {
        Class<?> superClass = clazz;

        for (;;) {
            if (!Modifier.isPublic(superClass.getModifiers())) {
                asmEnable = false;
                break;
            }

            superClass = superClass.getSuperclass();
            if (superClass == Object.class || superClass == null) {
                break;
            }
        }
    }

    if (clazz.getTypeParameters().length != 0) {
        asmEnable = false;
    }

    if (asmFactory.isExternalClass(clazz)) {
        asmEnable = false;
    }

    if (asmEnable) {
        if (clazz.isInterface()) {
            asmEnable = false;
        }
        DeserializeBeanInfo beanInfo = DeserializeBeanInfo.computeSetters(clazz, type);
        if (beanInfo.getFieldList().size() > 200) {
            asmEnable = false;
        }

        Constructor<?> defaultConstructor = beanInfo.getDefaultConstructor();
        if (defaultConstructor == null && !clazz.isInterface()) {
            asmEnable = false;
        }

        for (FieldInfo fieldInfo : beanInfo.getFieldList()) {
            if (fieldInfo.isGetOnly()) {
                asmEnable = false;
                break;
            }

            Class<?> fieldClass = fieldInfo.getFieldClass();
            if (!Modifier.isPublic(fieldClass.getModifiers())) {
                asmEnable = false;
                break;
            }

            if (fieldClass.isMemberClass() && !Modifier.isStatic(fieldClass.getModifiers())) {
                asmEnable = false;
            }
        }
    }

    if (asmEnable) {
        if (clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers())) {
            asmEnable = false;
        }
    }

    if (!asmEnable) {
        return new JavaBeanDeserializer(this, clazz, type);
    }

    try {
        return asmFactory.createJavaBeanDeserializer(this, clazz, type);
        // } catch (VerifyError e) {
        // e.printStackTrace();
        // return new JavaBeanDeserializer(this, clazz, type);
    } catch (NoSuchMethodException ex) {
        return new JavaBeanDeserializer(this, clazz, type);
    } catch (ASMException asmError) {
        return new JavaBeanDeserializer(this, clazz, type);
    } catch (Exception e) {
        throw new JSONException("create asm deserializer error, " + clazz.getName(), e);
    }
}
项目:itmarry    文件:ParserConfig.java   
public void putDeserializer(Type type, ObjectDeserializer deserializer) {
    derializers.put(type, deserializer);
}
项目:itmarry    文件:ParserConfig.java   
public ObjectDeserializer getDeserializer(FieldInfo fieldInfo) {
    return getDeserializer(fieldInfo.getFieldClass(), fieldInfo.getFieldType());
}
项目:itmarry    文件:DefaultJSONParser.java   
public void parseObject(Object object) {
    Class<?> clazz = object.getClass();
    Map<String, FieldDeserializer> setters = config.getFieldDeserializers(clazz);

    if (lexer.token() != JSONToken.LBRACE && lexer.token() != JSONToken.COMMA) {
        throw new JSONException("syntax error, expect {, actual " + lexer.tokenName());
    }

    for (;;) {
        // lexer.scanSymbol
        String key = lexer.scanSymbol(symbolTable);

        if (key == null) {
            if (lexer.token() == JSONToken.RBRACE) {
                lexer.nextToken(JSONToken.COMMA);
                break;
            }
            if (lexer.token() == JSONToken.COMMA) {
                if (isEnabled(Feature.AllowArbitraryCommas)) {
                    continue;
                }
            }
        }

        FieldDeserializer fieldDeser = setters.get(key);
        if (fieldDeser == null) {
            if (!isEnabled(Feature.IgnoreNotMatch)) {
                throw new JSONException("setter not found, class " + clazz.getName() + ", property " + key);
            }

            lexer.nextTokenWithColon();
            parse(); // skip

            if (lexer.token() == JSONToken.RBRACE) {
                lexer.nextToken();
                return;
            }

            continue;
        } else {
            Class<?> fieldClass = fieldDeser.getFieldClass();
            Type fieldType = fieldDeser.getFieldType();
            Object fieldValue;
            if (fieldClass == int.class) {
                lexer.nextTokenWithColon(JSONToken.LITERAL_INT);
                fieldValue = IntegerCodec.instance.deserialze(this, fieldType, null);
            } else if (fieldClass == String.class) {
                lexer.nextTokenWithColon(JSONToken.LITERAL_STRING);
                fieldValue = StringCodec.deserialze(this);
            } else if (fieldClass == long.class) {
                lexer.nextTokenWithColon(JSONToken.LITERAL_INT);
                fieldValue = LongCodec.instance.deserialze(this, fieldType, null);
            } else {
                ObjectDeserializer fieldValueDeserializer = config.getDeserializer(fieldClass, fieldType);

                lexer.nextTokenWithColon(fieldValueDeserializer.getFastMatchToken());
                fieldValue = fieldValueDeserializer.deserialze(this, fieldType, null);
            }

            fieldDeser.setValue(object, fieldValue);
        }

        if (lexer.token() == JSONToken.COMMA) {
            continue;
        }

        if (lexer.token() == JSONToken.RBRACE) {
            lexer.nextToken(JSONToken.COMMA);
            return;
        }
    }
}
项目:android_http_demo    文件:ParserConfig.java   
public IdentityHashMap<Type, ObjectDeserializer> getDerializers() {
    return derializers;
}
项目:android_http_demo    文件:ParserConfig.java   
public ObjectDeserializer createJavaBeanDeserializer(Class<?> clazz) {
    return createJavaBeanDeserializer(clazz, clazz);
}
项目:android_http_demo    文件:ParserConfig.java   
public void putDeserializer(Type type, ObjectDeserializer deserializer) {
    derializers.put(type, deserializer);
}
项目:android_http_demo    文件:ParserConfig.java   
public ObjectDeserializer getDeserializer(FieldInfo fieldInfo) {
    return getDeserializer(fieldInfo.getFieldClass(), fieldInfo.getFieldType());
}
项目:AndroidNio    文件:ParserConfig.java   
public IdentityHashMap<Type, ObjectDeserializer> getDerializers() {
    return derializers;
}
项目:AndroidNio    文件:ParserConfig.java   
public ObjectDeserializer createJavaBeanDeserializer(Class<?> clazz) {
    return createJavaBeanDeserializer(clazz, clazz);
}
项目:AndroidNio    文件:ParserConfig.java   
public void putDeserializer(Type type, ObjectDeserializer deserializer) {
    derializers.put(type, deserializer);
}
项目:AndroidNio    文件:ParserConfig.java   
public ObjectDeserializer getDeserializer(FieldInfo fieldInfo) {
    return getDeserializer(fieldInfo.getFieldClass(), fieldInfo.getFieldType());
}