安卓平台,开发使用kotlin, 操作json使用fastjson,使用过程中问题不断(或者说不如意,也许没get到...)。
以下方JSON结构为例
{
"key":...,
...
"list":[
{...},
{...},
...
{...}
]
}
list对应的数据类Test
data class Test(var id: Int?) : Serializable {
var name: String? = null
...
var createTime: Date? = null
}
一开始引用的是常规分支的1.2.58,在将data这个JSONArray反序列化成List
...
json.getJSONArray("list").toJavaList(Test::class.java)
运行失败
com.alibaba.fastjson.JSONException: default constructor not found.
后来加了 kotlin-reflect后,
com.alibaba.fastjson.JSONException: create instance error, public com.xxx.entity.Test(java.lang.Integer)
也尝试过添加默认构造方法,也不行。
后面看到有专门针对 android平台的分支,于是调整依赖为了1.1.71.android 还是运行失败
com.alibaba.fastjson.JSONException: length=1; index=1
希望能提供一份kotlin的集成使用介绍或者使用没有问题的指导一下,不用很详细。谢谢。