kryonet icon indicating copy to clipboard operation
kryonet copied to clipboard

KryoNet doesn't allow usage of Kryo 5.0.2's StdInstantiatorStrategy

Open Daburnell112 opened this issue 3 years ago • 3 comments

Been working on a project since 2010 in Java, has been migrated through all the versions since. It's essentially outsider art what I'm working on.

Ran into a problem where I tried to serialize a SynchronizedRandomAccessList after migrating from Vectors both of which are part of the Java Standard Library. Easy way to do this, and how I'm going to fix it is simply modify the source of the Java Standard Library to add a no arg constructor for this. I shouldn't have to do this with any library.

What I should be doing is changing Kryo to use the standard strategy to StdInstantiatorStrategy as described in the Kryo Documentation, however KryoNet is using Kryo 2.2.0, instead of 5.0.2 and as such it doesn't exist that far back.

How to fix this:

Update Kryonet to use Kryo 5.x

How to reproduce it:

Try to declare a Instantiate Strategy with the library.

Daburnell112 avatar Jan 30 '21 02:01 Daburnell112

Can't modifiy the Java Standard Library anyway, so yeah.

Tried a workaround by using SerializationInstaniationStrategy and I'm getting

Caused by: org.objenesis.ObjenesisException: java.io.NotSerializableException: class com.esotericsoftware.kryonet.FrameworkMessage$RegisterTCP not serializable

So yeah, I'm gonna have to switch libraries. Worked 7 years ago when the last version came out, but doesn't work now.

Daburnell112 avatar Jan 30 '21 04:01 Daburnell112

Hey @Daburnell112! This issue is basically a – more up to date – duplicate of #77 or any of the PRs that suggest updating the framework to Kryo 4.0. If you want to use Kryo 5 with Kryonet, your are best off taking a look at any of the forks that have already done this.

crykn avatar Jan 31 '21 17:01 crykn

Alright I figured it out.

I ended up implementing the KryoSerializer class and changing the list to an array, deleting the reference to the list, and then serializing the class with the array.

I think the problem I encountered was that the code button to download a zip uses an outdated version of Kryo in the Jar file that's with the distributable. I built the jar file from one of the branches into a jar file with the latest Kryo build and I think it works.

Apart from that, I think I figured it out so the issue is closed.

Daburnell112 avatar Feb 01 '21 08:02 Daburnell112