你可以通過如下地方下載下傳fastjson:
在maven中如何配置fastjson依賴
fastjson最新版本都會釋出到maven中央倉庫,你可以直接依賴。
android版本
fastjson入口類是com.alibaba.fastjson.json,主要的api是json.tojsonstring,和parseobject。
序列化:
反序列化:
泛型反序列化:
自行做性能測試時,關閉循環引用檢測的功能。
這裡有jackson作者cowtowncoder等人對fastjson的性能評價:
<a href="https://groups.google.com/forum/#!topic/java-serialization-benchmarking/8es1koquahw">https://groups.google.com/forum/#!topic/java-serialization-benchmarking/8es1koquahw</a>
不需要,fastjson的序列化和反序列化都不需要做特别配置,唯一的要求是,你序列化的類符合java bean規範。
fastjson處理日期的api很簡單,例如:
使用iso-8601日期格式
全局修改日期格式
反序列化能夠自動識别如下日期格式:
iso-8601日期格式
yyyy-mm-dd
yyyy-mm-dd hh:mm:ss
yyyy-mm-dd hh:mm:ss.sss
毫秒數字
毫秒數字字元串
.net json日期格式
new date(198293238)
關于定制序列化,詳細的介紹看這裡:
<a href="https://github.com/alibaba/fastjson/wiki/%e5%ae%9a%e5%88%b6%e5%ba%8f%e5%88%97%e5%8c%96">https://github.com/alibaba/fastjson/wiki/%e5%ae%9a%e5%88%b6%e5%ba%8f%e5%88%97%e5%8c%96</a>
使用serializerfeature.disablecircularreferencedetect特性關閉引用檢測和生成。例如:
fastjson提供了browsercompatible這個配置,打開之後,所有的中文都會序列化為uxxxx這種格式,位元組數會多一些,但是能相容ie 6。
<a href="https://github.com/alibaba/fastjson/wiki">https://github.com/alibaba/fastjson/wiki</a>