Issue with deserialization of ImmutableMap

869 views
Skip to first unread message

Nandaja A

unread,
Jun 24, 2014, 12:28:33 AM6/24/14
to kryo-...@googlegroups.com
Hi, 

I am using Kryo to deserialize an object which has one of its fields as an instance of com.google.common.collect.ImmutableMap class. When trying to read into an object from a Kryo serialized entry in the cache, it fails to do so with an UnsupportedOperationException on the put invocation on the map. 

Serialization trace:

idMap (*mypackagename ) 

com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException

Serialization trace:

idMap (*mypackagename ) 

        at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)

        at com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer.read(CompatibleFieldSerializer.java:83)

        at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:776)


How can I deserialize an instance of an ImmutableMap with Kryo ? Any pointers would be helpful. 

Thanks, 
Nandaja

mongonix

unread,
Jun 24, 2014, 3:18:13 AM6/24/14
to kryo-...@googlegroups.com
Hi,
Since this map class does not implement any "put" operations, you need to create your custom Kryo serializer for this class, which should not be too difficult in this case. I'd suggest that you derive your serializer from Kryo's MapSerialzer and simply override the read method.
In the read method, you read the elements from a stream and use the builder API of ImmutableMap to create an instance of the map. That's it.

Once your serializer is written, you need to register it with Kryo e.g. using
kryo.register(ImmutableMap.class, YourCustomSerializer.class);

I hope this helps you to proceed further.

-Leo

Martin Grotzke

unread,
Jun 24, 2014, 3:53:50 AM6/24/14
to kryo-users

This would also be a nice contribution to https://github.com/magro/kryo-serializers :-)

Cheers,
Martin

--
You received this message because you are subscribed to the "kryo-users" group.
http://groups.google.com/group/kryo-users
---
You received this message because you are subscribed to the Google Groups "kryo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kryo-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nandaja A

unread,
Jun 24, 2014, 12:36:27 PM6/24/14
to kryo-...@googlegroups.com
Thanks, Leo & Martin. I will keep a stab at the custom serializer and once done, see if I can contribute it to the kryo-serializers project ! 

Oscar Boykin

unread,
Jun 24, 2014, 1:15:54 PM6/24/14
to kryo-...@googlegroups.com
Nandaja,

Also ping us when you do this. Chill has had an open issue for this for a while:


(chill is a set of serializers and a configuration framework for Kryo with some special focus on Hadoop, Storm and Akka).


--
You received this message because you are subscribed to the "kryo-users" group.
http://groups.google.com/group/kryo-users
---
You received this message because you are subscribed to the Google Groups "kryo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kryo-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Oscar Boykin :: @posco :: http://twitter.com/posco
Reply all
Reply to author
Forward
0 new messages