本文整理汇总了Java中com.alibaba.fastjson.util.DeserializeBeanInfo类的典型用法代码示例。如果您正苦于以下问题:Java DeserializeBeanInfo类的具体用法?Java DeserializeBeanInfo怎么用?Java DeserializeBeanInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeserializeBeanInfo类属于com.alibaba.fastjson.util包,在下文中一共展示了DeserializeBeanInfo类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JavaBeanDeserializer
import com.alibaba.fastjson.util.DeserializeBeanInfo; //导入依赖的package包/类
public JavaBeanDeserializer(ParserConfig config, Class<?> clazz, Type type) {
this.feildDeserializerMap = new IdentityHashMap();
this.fieldDeserializers = new ArrayList();
this.sortedFieldDeserializers = new ArrayList();
this.clazz = clazz;
this.beanInfo = DeserializeBeanInfo.computeSetters(clazz, type);
for (FieldInfo fieldInfo : this.beanInfo.getFieldList()) {
addFieldDeserializer(config, clazz, fieldInfo);
}
for (FieldInfo fieldInfo2 : this.beanInfo.getSortedFieldList()) {
this.sortedFieldDeserializers.add((FieldDeserializer) this.feildDeserializerMap.get(fieldInfo2.getName().intern()));
}
}
示例2: Context
import com.alibaba.fastjson.util.DeserializeBeanInfo; //导入依赖的package包/类
public Context(String className, ParserConfig config, DeserializeBeanInfo beanInfo, int initVariantIndex) {
this.className = className;
this.clazz = beanInfo.getClazz();
this.variantIndex = initVariantIndex;
this.beanInfo = beanInfo;
this.fieldInfoList = new ArrayList(beanInfo.getFieldList());
}
示例3: Context
import com.alibaba.fastjson.util.DeserializeBeanInfo; //导入依赖的package包/类
public Context(String className, ParserConfig config, DeserializeBeanInfo beanInfo, int initVariantIndex){
this.className = className;
this.clazz = beanInfo.getClazz();
this.variantIndex = initVariantIndex;
this.beanInfo = beanInfo;
fieldInfoList = new ArrayList<FieldInfo>(beanInfo.getFieldList());
}
示例4: gen
import com.alibaba.fastjson.util.DeserializeBeanInfo; //导入依赖的package包/类
@Override
public void gen() throws IOException {
beanInfo = DeserializeBeanInfo.computeSetters(clazz, type);
genClassName = clazz.getSimpleName() + "GenDecoder";
print("package ");
print(clazz.getPackage().getName());
println(";");
println();
println("import java.lang.reflect.Type;");
println();
println("import com.alibaba.fastjson.parser.DefaultJSONParser;");
println("import com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask;");
println("import com.alibaba.fastjson.parser.ParserConfig;");
println("import com.alibaba.fastjson.parser.Feature;");
println("import com.alibaba.fastjson.parser.JSONLexerBase;");
println("import com.alibaba.fastjson.parser.JSONToken;");
println("import com.alibaba.fastjson.parser.ParseContext;");
println("import com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer;");
println("import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;");
println();
print("public class ");
print(genClassName);
print(" extends ASMJavaBeanDeserializer implements ObjectDeserializer {");
incrementIndent();
println();
genConstructor();
genCreateInstance();
genDeserialze();
endClass();
}
示例5: createJavaBeanDeserializer
import com.alibaba.fastjson.util.DeserializeBeanInfo; //导入依赖的package包/类
public ObjectDeserializer createJavaBeanDeserializer(ParserConfig config, Class<?> clazz, Type type)
throws Exception {
if (clazz.isPrimitive()) {
throw new IllegalArgumentException("not support type :" + clazz.getName());
}
String className = getGenClassName(clazz);
ClassWriter cw = new ClassWriter();
cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, className, getType(ASMJavaBeanDeserializer.class), null);
DeserializeBeanInfo beanInfo = DeserializeBeanInfo.computeSetters(clazz, type);
_init(cw, new Context(className, config, beanInfo, 3));
_createInstance(cw, new Context(className, config, beanInfo, 3));
_deserialze(cw, new Context(className, config, beanInfo, 4));
_deserialzeArrayMapping(cw, new Context(className, config, beanInfo, 4));
byte[] code = cw.toByteArray();
// org.apache.commons.io.IOUtils.write(code, new java.io.FileOutputStream(
// "/usr/alibaba/workspace-3.7/fastjson-asm/target/classes/"
// + className + ".class"));
Class<?> exampleClass = classLoader.defineClassPublic(className, code, 0, code.length);
Constructor<?> constructor = exampleClass.getConstructor(ParserConfig.class, Class.class);
Object instance = constructor.newInstance(config, clazz);
return (ObjectDeserializer) instance;
}
示例6: JavaBeanDeserializer
import com.alibaba.fastjson.util.DeserializeBeanInfo; //导入依赖的package包/类
public JavaBeanDeserializer(ParserConfig config, Class<?> clazz, Type type){
this.clazz = clazz;
this.type = type;
beanInfo = DeserializeBeanInfo.computeSetters(clazz, type);
for (FieldInfo fieldInfo : beanInfo.getFieldList()) {
addFieldDeserializer(config, clazz, fieldInfo);
}
}
示例7: getBeanInfo
import com.alibaba.fastjson.util.DeserializeBeanInfo; //导入依赖的package包/类
public DeserializeBeanInfo getBeanInfo() {
return this.beanInfo;
}
示例8: createJavaBeanDeserializer
import com.alibaba.fastjson.util.DeserializeBeanInfo; //导入依赖的package包/类
public ObjectDeserializer createJavaBeanDeserializer(ParserConfig config, Class<?> clazz, Type type) throws Exception {
Exception ex;
Throwable th;
if (clazz.isPrimitive()) {
throw new IllegalArgumentException("not support type :" + clazz.getName());
}
String className = getGenClassName(clazz);
ClassWriter cw = new ClassWriter();
cw.visit(49, 33, className, "com/alibaba/fastjson/parser/deserializer/ASMJavaBeanDeserializer", null);
DeserializeBeanInfo beanInfo = DeserializeBeanInfo.computeSetters(clazz, type);
_init(cw, new Context(className, config, beanInfo, 3));
_createInstance(cw, new Context(className, config, beanInfo, 3));
_deserialze(cw, new Context(className, config, beanInfo, 4));
_deserialzeArrayMapping(cw, new Context(className, config, beanInfo, 4));
byte[] code = cw.toByteArray();
if (JSON.DUMP_CLASS != null) {
FileOutputStream fos = null;
try {
FileOutputStream fos2 = new FileOutputStream(JSON.DUMP_CLASS + File.separator + className + ".class");
try {
fos2.write(code);
if (fos2 != null) {
fos2.close();
}
} catch (Exception e) {
ex = e;
fos = fos2;
try {
System.err.println("FASTJSON dump class:" + className + "失败:" + ex.getMessage());
if (fos != null) {
fos.close();
}
return (ObjectDeserializer) this.classLoader.defineClassPublic(className, code, 0, code.length).getConstructor(new Class[]{ParserConfig.class, Class.class}).newInstance(new Object[]{config, clazz});
} catch (Throwable th2) {
th = th2;
if (fos != null) {
fos.close();
}
throw th;
}
} catch (Throwable th3) {
th = th3;
fos = fos2;
if (fos != null) {
fos.close();
}
throw th;
}
} catch (Exception e2) {
ex = e2;
System.err.println("FASTJSON dump class:" + className + "失败:" + ex.getMessage());
if (fos != null) {
fos.close();
}
return (ObjectDeserializer) this.classLoader.defineClassPublic(className, code, 0, code.length).getConstructor(new Class[]{ParserConfig.class, Class.class}).newInstance(new Object[]{config, clazz});
}
}
return (ObjectDeserializer) this.classLoader.defineClassPublic(className, code, 0, code.length).getConstructor(new Class[]{ParserConfig.class, Class.class}).newInstance(new Object[]{config, clazz});
}
示例9: createJavaBeanDeserializer
import com.alibaba.fastjson.util.DeserializeBeanInfo; //导入依赖的package包/类
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);
}
}
示例10: getBeanInfo
import com.alibaba.fastjson.util.DeserializeBeanInfo; //导入依赖的package包/类
public DeserializeBeanInfo getBeanInfo() {
return beanInfo;
}
示例11: createJavaBeanDeserializer
import com.alibaba.fastjson.util.DeserializeBeanInfo; //导入依赖的package包/类
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);
}
}