序列化番石榴的不可变表 [英] Serializing Guava's ImmutableTable
问题描述
我正在使用 Guava 的17.0版本,尤其是新的收藏类型.尝试通过Socket
编写ImmutableTable
时,我意识到该类及其具体实现似乎不可序列化.
I am using the version 17.0 of Guava, especially the new collection types. While trying to write an ImmutableTable
through a Socket
, I realized that the class and its concrete implementations do not seem to be serializable.
但是,以下两张票证似乎表明开发人员已意识到该问题:
However, the two following tickets seem to indicate that the developers are aware of the issue:
- Issue 1264
- Issue 1562
你们中有人对包含ImmutableTable
属性的类进行序列化吗?我该怎么做,而又不使用Map
的Map
?
Do any of you serialize classes containing ImmutableTable
attributes? How could I do this, without resorting to using a Map
of Map
s?
推荐答案
即使ImmuttableTable无法序列化,您也可以始终使用表实现.然后反序列化之后,使用ImmutableTable.copyOf(deserialized)再次获取ImmutableTable.不完全优雅,但实施起来很简单.
Even though ImmuttableTable isn't serializable, you could always use a HashBasedTable or one of the other Table implementations. And then after deserialization, use ImmutableTable.copyOf(deserialized) to get the ImmutableTable again. Not exactly elegant, but simple enough to implement.
这篇关于序列化番石榴的不可变表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!