Fastjson Android design


Fastjson Android is designed with ASMDeserializerFactory

ASMDeserializerFactory is a Deserializer used to dynamically use ASM to generate JavaBeans. It is specially optimized for the characteristics of each class to obtain the fastest performance.

1. Limitations

Currently ASMDeserializerFactory cannot run on the dalvik virtual machine of Android and the lemur virtual machine of Alibaba Cloud OS.

Virtual machineWhether it supportsOracle HotspotSupportdalvikNot supportedlemurNot supported##
public class ASMUtils {
     public static boolean isAndroid(String vmName) {
        String lowerVMName = vmName.toLowerCase();
        return lowerVMName.contains("dalvik") 
                 || lowerVMName.contains("lemur") // aliyun-vm name
                 ;
     }
}

Currently ASMDeserializerFactory does not support JavaBeans with more than 200 fields. When doing deserialization, you need to define local variables to save the results of parse. The current asm framework cannot define more than 256 variables. The current conservative approach is that if the number of fields exceeds 200, ASMDeserializerFactory is not used.

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

If class There is a default public constructor, use new directly to create an instance; otherwise use JavaBeanDeserializer.createInstance(DefaultJSONParser, Type) to create an instance.

The flag of each 32 variables is stored in an int type variable, _setFlag and _isFlag are used to set and read whether it is parsed respectively.