registering private inner classes

1,079 views
Skip to first unread message

ua stan

unread,
Apr 6, 2011, 12:45:38 PM4/6/11
to kryo-...@googlegroups.com
Hi

how would I register class with kryo if it's private inner class? I'm getting this error 
Caused by: java.lang.IllegalArgumentException: Class is not registered: java.util.Collections$EmptyList
at com.esotericsoftware.kryo.Kryo.getRegisteredClass(Kryo.java:319)
at com.esotericsoftware.kryo.Kryo.writeClass(Kryo.java:374)
at com.esotericsoftware.kryo.serialize.FieldSerializer.writeObjectData(FieldSerializer.java:173)
... 35 more

Martin Grotzke

unread,
Apr 7, 2011, 3:23:49 AM4/7/11
to kryo-...@googlegroups.com
Hi,

you can use https://github.com/magro/kryo-serializers for this, it
provides several serializers for standard jdk classes, for
Collections.EMPTY_LIST there's the CollectionsEmptyListSerializer.

To register the serializer you have to add

kryo.register( Collections.EMPTY_LIST.getClass(), new
CollectionsEmptyListSerializer() );

Cheers,
Martin

> --
> You received this message because you are subscribed to the "kryo-users"
> group.
> http://groups.google.com/group/kryo-users

--
Martin Grotzke
http://twitter.com/martin_grotzke

signature.asc

ua stan

unread,
Apr 7, 2011, 3:51:58 AM4/7/11
to kryo-...@googlegroups.com
Hi
Thanks for the help. However the question wasn't quite correct. Since this is my first try with Kryo I didnt figure out at first, this code does trick
kryo.register(Collections.EMPTY_LIST.getClass());

So standard serialized works out good. And this CollectionsEmptyListSerializer is for optimization, which is handy but not my goal right now.

Thank you
stan

Martin Grotzke

unread,
Apr 7, 2011, 4:04:15 AM4/7/11
to kryo-...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Great it works for you,

cheers,
Martin

> --
> You received this message because you are subscribed to the "kryo-users"
> group.
> http://groups.google.com/group/kryo-users

- --
Martin Grotzke
http://twitter.com/martin_grotzke
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk2db/8ACgkQ7FvOl7Te+pZT5ACghWZRNKddMCv1w3ED2clgL9Qp
QOQAnA9kDLpzSNA2zPQtuWNh00TrCcq7
=dkoo
-----END PGP SIGNATURE-----

ua stan

unread,
Apr 18, 2011, 3:56:25 AM4/18/11
to kryo-...@googlegroups.com
Hi

kryo complaints with message  Caused by: java.lang.IllegalArgumentException: Class is not registered: ...
How would you get over this if class in error message is package private, like in example below

Caused by: java.lang.IllegalArgumentException: Class is not registered: java.util.concurrent.locks.ReentrantLock$NonfairSync

Martin Grotzke

unread,
Apr 18, 2011, 4:14:42 AM4/18/11
to kryo-...@googlegroups.com
Hi,

this error pops up as the ReentrantLock is serialized using FieldSerializer.

You can write a custom serializer for ReentrantLock that correctly
handles this class and register this serializer for ReentrantLock at kryo.

I'd say that this is also a good idea as with the fieldserializer it
might happen that you serialize/deserialize it in a locked state, but
probably you'd expect such stuff to start "fresh" / unlocked when
deserialized.

Often the methods for java serialization (writeObject/readObject) in
such classes show you how to implement the custom serializer.

There's already a project that provides several serializers for standard
jdk types: https://github.com/magro/kryo-serializers
So this might also be a good home for a ReentrantLockSerializer if it
wouldn't make it into kryo itself.

Cheers,
Martin

> --
> You received this message because you are subscribed to the "kryo-users"
> group.
> http://groups.google.com/group/kryo-users

--
Martin Grotzke
http://twitter.com/martin_grotzke

signature.asc
Reply all
Reply to author
Forward
0 new messages