'Kryo Serializer
I Have some java code that currently works like this:
Client:
...
serializer.serialize(new ClientGetAllRequest(keys));
Server:
Object request = serializer.getObject();
...
Where the ClientGetAllRequest Class is just a class with a field List<String> keys (Similarly for PutAll but it's a Map<String,byte[]> not a List).
The serializer works like this:
public class KryoSerializer {
private Output output;
private Input input;
private Kryo kryo;
public KryoSerializer() {
kryo = new Kryo();
kryo.register(byte[].class);
kryo.register(ArrayList.class);
kryo.register(HashMap.class);
kryo.register(HashSet.class);
kryo.register(ClientRequest.class);
kryo.register(ClientError.class);
kryo.register(ClientGetAllRequest.class);
kryo.register(ClientPutAllRequest.class);
kryo.register(ClientPutAllResponse.class);
kryo.register(ClientGetAllResponse.class);
//(Here actually many other classes are registered for another part of the code irrelevant to this question)
kryo.setRegistrationRequired(true);
}
public void setInputStream(InputStream inputStream) {
this.input = new Input(inputStream, Config.getConfig().max_object_size);
}
public void setOutputStream(OutputStream outputStream) {
this.output = new Output(outputStream, Config.getConfig().max_object_size);
}
public void serialize(Object object) throws IOException {
kryo.writeClassAndObject(this.output, object);
this.output.flush();
this.output.getOutputStream().flush();
}
public Object getObject() {
return kryo.readClassAndObject(input);
}
}
I want to add a field String client_thread_id to the request but every time i try i get a serializing error, where for some reason the serializer at the server side tries to read one of the keys in the list as a class:
com.esotericsoftware.kryo.KryoException: Unable to find class: user1512450
I'm not sure what I'm doing wrong but I'm not very familiar on how to work with Kryo Serializers. Does anyone know where I should be looking to solve this error?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
