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

项目: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();
    }
}
项目: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();
    }
}
项目: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    文件:DefaultFieldDeserializerBug569.java   
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
    if (fieldValueDeserilizer == null) {
        getFieldValueDeserilizer(parser.getConfig());
    }

    Type fieldType = fieldInfo.fieldType;
    if (objectType instanceof ParameterizedType) {
        ParseContext objContext = parser.getContext();
        objContext.type = objectType;
        fieldType = FieldInfo.getFieldType(this.clazz, objectType, fieldType);
    }

    // ContextObjectDeserializer
    Object value;
    if (fieldValueDeserilizer instanceof JavaBeanDeserializer) {
        JavaBeanDeserializer javaBeanDeser = (JavaBeanDeserializer) fieldValueDeserilizer;
        value = javaBeanDeser.deserialze(parser, fieldType, fieldInfo.name, fieldInfo.parserFeatures);
    } else {
        if (this.fieldInfo.format != null && fieldValueDeserilizer instanceof ContextObjectDeserializer) {
            value = ((ContextObjectDeserializer) fieldValueDeserilizer) //
                    .deserialze(parser, fieldType,
                            fieldInfo.name,
                            fieldInfo.format,
                            fieldInfo.parserFeatures);
        } else {
            value = fieldValueDeserilizer.deserialze(parser, fieldType, fieldInfo.name);
        }
    }
    if (parser.getResolveStatus() == DefaultJSONParser.NeedToResolve) {
        DefaultJSONParser.ResolveTask task = parser.getLastResolveTask();
        task.fieldDeserializer = this;
        task.ownerContext = parser.getContext();
        parser.setResolveStatus(DefaultJSONParser.NONE);
    } else {
        if (object == null) {
            fieldValues.put(fieldInfo.name, value);
        } else {
            setValue(object, value);
        }
    }
}
项目: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 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);
    }
}
项目: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 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);
    }
}