300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Could not read JSON: Cannot construct instance of `java.util.ArrayList$SubList`

Could not read JSON: Cannot construct instance of `java.util.ArrayList$SubList`

时间:2022-09-01 08:07:15

相关推荐

Could not read JSON: Cannot construct instance of `java.util.ArrayList$SubList`

场景:使用Redis缓存,将方法的返回值缓存.方法内部调用了SubList()这个方法.

原因:subList方法返回的是一个List,这个List是一个interface,继承自Collection, 而且Collection也是interface,是没有实现Serializable接口的,所以不能序列化/反序列化。

解决方法:

// 原错误代码

bannerList = bannerList.subList(0, SLIDING_SIZE);

// 修改后的正确代码

bannerList = new ArrayList<>(bannerList.subList(0, SLIDING_SIZE));

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。