[SOLVED] Problems sending a Set via SpiderMonkey

I tried sending a java.util.Set from my server to my client today and got the following error:


21-dec-2010 22:24:59 com.jme3.network.serializing.serializers.CollectionSerializer readObject

WARNING: [Serializer][???] Could not determine collection type. Using ArrayList.

21-dec-2010 22:24:59 com.jme3.network.connection.ConnectionRunnable$1 uncaughtException

SEVERE: Uncaught exception thrown in Thread[Thread-5,5,main]

java.lang.IllegalArgumentException: Can not set java.util.Set field com.ractoc.opengamefinder.api.plugins.results.network.ChatEnterRoomNetworkMessageResult.roomMemberList to java.util.ArrayList

at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)

at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)

at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)

at java.lang.reflect.Field.set(Field.java:657)

at com.jme3.network.serializing.serializers.FieldSerializer.readObject(FieldSerializer.java:110)

at com.jme3.network.serializing.Serializer.readClassAndObject(Serializer.java:244)

at com.jme3.network.connection.TCPConnection.read(TCPConnection.java:194)

at com.jme3.network.connection.Connection.run(Connection.java:124)

at com.jme3.network.connection.ConnectionRunnable.run(ConnectionRunnable.java:86)

at java.lang.Thread.run(Thread.java:619)


It seems the serializer doesn’t know Sets yet.

Any chance these can be added soonish, or would I be better off converting to and from an ArrayList?


Ok, I found the cause of the problem, and the solution as well…

Every Serializer is registered to a Class. All except two, the Collection and the Map serializer are registered against their interface. Because the CollectionSerializer and MapSerializer both use Class.newInstance() to create a new instance of the serialized class, this won’t work. newInstance is not availlable on an Interface.

The solution is simple, but requires some work. The registration on the Interface needs to be removed and a registration for each collection class and each map class needs to be added. I already tested this for the TreeSet class I’m trying to send and it works perfectly.

The question then remains is: do we want this whole list of registrations inside the spidermonkey serializer, or do we let the developer add those he needs manuallly?

1 Like

They’ve been added. To answer your question Ractoc, we put it in Serializer itself. Doesn’t really make a difference to SM, and dev’s wont have to do it themselves now.