Hello,
I'm fairly new to Kryo (and java) and I'm facing the following issue.
I'm trying to deserialize an ArrayList of objects I'm getting as a byte array from a zeromq socket.
The objects at the server and client are the same, i.e. they use the same class library. The server and the client use the same version of Kryo (2.22-SNAPSHOT):
// Server
void selectSomeClassRecords(ZMQ.Socket socket){
...
// query the DB
Selects selects = new Selects();
List<SomeClass> someClassRecords = (ArrayList<SomeClass>)selects.selectSomeClassRecords();
kryo.register(SomeClass.class);
kryo.register(someClassRecords.getClass());
kryo.writeObject(output, someClassRecords);
kryo.reset();
output.flush();
byte[] msg = ((ByteArrayOutputStream)output.getOutputStream()).toByteArray();
output.close();
socket.send(msg, 0);
...
}
// Client
private void querySomeClass(ZMQ.Socket socket)
{
...
try
{
// receive the buffer
byte[] buffer = socket.recv(0);
// restore the buffer into an object
List<SomeClass> someClassRecords = null;
kryo.register(SomeClass.class);
kryo.register(someClassRecords.getClass());
Input input = new Input(new ByteArrayInputStream(buffer), buffer.length);
kryo.register(SomeClass.class);
kryo.register(someClassRecords.getClass());
someClassRecords = new ArrayList<StudyDesc>(kryo.readObject(input, someClassRecords.getClass()));
kryo.reset();
}
catch (Exception e)
{
e.printStackTrace();
}
i.close();
...
}
"SomeClass" itself contains references to other classes, some of which contain generic ArrayLists. All the objects in the hierarchy and in the collections are plain java objects and may inherit from other simple classes, all in all is about 8 to 10 levels deep.
The buffer I get back is around 3K and if I make it into a String, just to inspect it, it seems to contain the information I expect, however when I tried to deserialize the buffer with the above query method I get:
com.esotericsoftware.kryo.KryoException: Encountered unregistered class ID: 12
at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:119)
at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:656)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:767)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:112)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:1)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:672)
at com.neb.test.App.querySomeClass(App.java:10296)
at com.neb.test.App.run(App.java:14128)
at com.neb.test.App.main(App.java:14139)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:722)
I have Kryo#setAutoRest(false) in both client and server, that is the only explicit setting I have.
I'd appreciate any pointers you could give me on what I'm missing/doing wrong or on ways I could get a more detailed error output (e.g. how to know which one is class ID 12?)