Gson toJson FromJson 异常

30 篇文章 0 订阅

当一个Bean里面 还有 WeakReference 或者 SoftReference,使用Gson 2.5的 toJson 或者FromJson会导致:

 StackOverflowError 错误

 

参见 这个http://blog.csdn.net/s278777851/article/details/9850677

 

原因:

GSON版本 2.2.2, 在android 4.2之后会报错StackOverflowError,最后发现是Gson的bug,https://code.google.com/p/google-gson/issues/detail?id=440

 

Comment #12:

I believe it was in API 17 that the internals of WeakReference and SoftReference changed to be self-referent, which would trigger this. Are you using Gson to serialize a WeakReference or SoftReference? If you are, you should write your own TypeAdapter for those types.

 

解决方法一: 未测试

我用 GSON 1.7.1版本替换掉2.2.2版本就解决了。 1.7.1下载地址 https://code.google.com/p/google-gson/downloads/detail?name=google-gson-1.7.1-release.zip&can=2&q=

 

解决方法二:

// 用于界面更新
public transient WeakReference<View> m_oViewL = null;

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值