Java序列化问题,同时使用番石榴Lists.transform [英] Java Serialization Problems, while using guava Lists.transform

查看:95
本文介绍了Java序列化问题,同时使用番石榴Lists.transform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不序列化一个复杂的对象,但是它的组成部分之一是不可序列化的(第三方图形对象),因此我创建了这个Graph类的自定义可序列化版本,并使用了Guava List转换来转换不可序列化的对象到自定义对象.序列化writeObject仍然失败.我有兴趣知道为什么吗?我的假设是Lists.transform懒惰地执行其操作(持有对原始对象的隐藏引用.)

I had to serialize a complex object, but one of its component was non-serializable ( a third party graph object), so I created a custom serializable version of this Graph class and used Guava List transform to convert the non-serializable object to the custom objects. The serialization writeObject still failed. I will be interested to know why? My assumption is that the Lists.transform performs its operation Lazily (Holding an hidden reference to the orginal object.)

也有解决此问题的方法吗?

Also is there an workaround for this problem ?

推荐答案

Lists.transform()确实像您怀疑的那样执行缓慢.您可以做以下其中一项

Lists.transform() does perform lazily as you suspected. You could do one of

Lists.newArrayList(Lists.transform(...))

或者,如果您想要一个不变的版本,

or, if you want an immutable version,

ImmutableList.copyOf(Lists.transform(...))

,然后序列化结果列表.

and then serialize the resulting list.

这篇关于Java序列化问题,同时使用番石榴Lists.transform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆