TimurMahammadov / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

StandardMultimap$RandomAccessWrappedList is not Serializable #36

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi
I got this exception:
    java.io.NotSerializableException:
com.google.common.collect.StandardMultimap$RandomAccessWrappedList
java.rmi.MarshalException: error marshalling arguments; nested exception is: 
    java.io.NotSerializableException:
com.google.common.collect.StandardMultimap$RandomAccessWrappedList
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
....

Which is surprising, why shouldn't this RandomAccessWrappedList be
Serializable?

I have a ListMultimap<String,Enum> and I need to send the list of enums to
my EJB Server. It worked fine when I was using a HashMap<String,List<Enum>>.

List<Enum> = myMultimap.get(state);
This list is not serializable.

Is it by design?

Thanks
Benoit.

Original issue reported on code.google.com by beno...@gmail.com on 6 Nov 2007 at 3:49

GoogleCodeExporter commented 9 years ago
Here's the difficulty in making it serializible. Multimap.get() returns a live 
view
into the multimap, which changes when the multimap changes. How can we serialize
Multimap.get(key) for a single key, apart from serializing the entire multimap? 
For
similar reasons, the views of the JDK collections, such as Map.keySet(), aren't
serializable.

However, your desire to serialize the values of a multimap key is totally 
reasonable.
Since serialization doesn't seem to be technically feasible, unless we rewrite
StandardMultimap, we should add documentation explaining that the collections
returned by our Multimap.get() implementations are not serializible.

There is a simple workaround: copy the Multimap.get() values into a JDK 
collection
class, which you then serialize.

Original comment by jared.l....@gmail.com on 6 Nov 2007 at 5:33

GoogleCodeExporter commented 9 years ago

Original comment by kevin...@gmail.com on 6 Nov 2007 at 5:47

GoogleCodeExporter commented 9 years ago
Documentation would be welcomed indeed. I've come to the same conclusion and
implemented what you suggested as a workaround.

May be adding a method getCopy(key) or something similar could be useful when 
the
return may be sent across the network? or may be able to create a Multimap which
would return serializable lists?

Thanks for your prompt reply.

Original comment by beno...@gmail.com on 6 Nov 2007 at 6:28

GoogleCodeExporter commented 9 years ago
We're considering changes like those.

Thanks for your suggestions!

Original comment by jared.l....@gmail.com on 6 Nov 2007 at 10:15