Manual tutorial FastJson
/ Fastjson Android版本
Fastjson Android版本
Fastjson Android版本
Fastjson提供Android版本,和標(biāo)準(zhǔn)版本相比,Android版本去掉一些Android虛擬機(jī)dalvik不支持的功能,使得jar更小,同時(shí)針對(duì)dalvik做了很多性能優(yōu)化,包括減少方法調(diào)用等。parse為JSONObject/JSONArray時(shí)比原生org.json速度快,序列化反序列化JavaBean性能比jackson/gson性能更好。
下載
通過(guò) Maven:
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>VERSION_CODE</version> </dependency>
或者 Gradle:
compile 'com.alibaba:fastjson:VERSION_CODE'
用 這里 或者 這里 或者 這里 的真實(shí)發(fā)行版本號(hào), 替換 VERSION_CODE
, 例如 1.1.54.android
Android版本中去掉的功能
1. ASM
Dalvik虛擬機(jī)的字節(jié)碼格式和Java SE不一樣,目前的ASM動(dòng)態(tài)優(yōu)化無(wú)法在Android上實(shí)現(xiàn)。
2. AWT
Android上的Dalvik虛擬機(jī)不支持awt,所以去掉標(biāo)準(zhǔn)版本的awt相關(guān)類序列化和反序列化的支持。
3. AtomicXXX
AtomicXXX不應(yīng)該作為POJO的屬性,不常用,所以在Android版本中去掉了。
4. 不支持Clob對(duì)象序列化。
5. JSONPObject
這個(gè)功能用于web jsonp數(shù)據(jù)生成,不常用于android客戶端,所以去掉。
6. 不支持Reference字段類型序列化和反序列化,比如WeakReference/SoftReference/AtomicReference,這些類型不常用用作POJO的屬性,所以去掉了。
7. 以下方法不常用,不支持
public abstract class JSON { public static parseObject(byte[] input, int off, int len, CharsetDecoder charsetDecoder, Type clazz, Feature... features) { ... } public static Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) {} public static Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, Feature...features) {} public static Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) {} } // JSONSerializerMap已廢棄,不支持 com.alibaba.fastjson.serializer.JSONSerializer.JSONSerializer(JSONSerializerMap)
8. 一些廢棄的類不支持
com.alibaba.fastjson.parser.JavaBeanMapping 使用com.alibaba.fastjson.parser.ParserConfig代替com.alibaba.fastjson.serializer.JSONSerializerMap 使用com.alibaba.fastjson.serializer.SerializeConfig代替com.alibaba.fastjson.parser.DefaultExtJSONParser 使用com.alibaba.fastjson.parser.DefaultJSONParser代替
9. 一些廢棄方法不支持
class com.alibaba.fastjson.JSONWriter { @Deprecated public void writeStartObject(); @Deprecated public void writeEndObject(); @Deprecated public void writeStartArray(); @Deprecated public void writeEndArray(); }