Reputation: 354
We are trying to use Kryo Serializer to serialize our application object to push them in a kafka stream.
The serialization code has
private ThreadLocal<Kryo> kryos = new ThreadLocal<Kryo>() {
protected Kryo initialValue() {
Kryo kryo = new Kryo();
kryo.addDefaultSerializer(MyApp.class, new MyAppKyroSerializer());
return kryo;
};
};
The serialize method is:
@Override
public byte[] serialize(String topic, MyApp data) {
ByteBufferOutput output = new ByteBufferOutput(100);
kryos.get().writeObject(output, data);
return output.toBytes();
}
While executing the Application we are getting the following IllegalAccessError:
Exception in thread "main" java.lang.IllegalAccessError: tried to access field com.esotericsoftware.kryo.io.Output.capacity from class com.esotericsoftware.kryo.io.ByteBufferOutput
at com.esotericsoftware.kryo.io.ByteBufferOutput.<init>(ByteBufferOutput.java:66)
at com.esotericsoftware.kryo.io.ByteBufferOutput.<init>(ByteBufferOutput.java:58)
at com.mycom.serializer.MyAppSerializer.serialize(MyAppSerializer.java:43)
This is strange because ByteBufferOutput extends Output and capacity is a protected field.
Upvotes: 1
Views: 409
Reputation: 1867
As it said in Java Documentation for IllegalAccessError
:
Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
So suggestion would be to check if all Kryo libs (in your project) are compliant with each other and belong to one-version of Kryo.
Upvotes: 1
Reputation: 11
public byte[] serialize(String topic, Myapp data) {
Output output = new Output(100);
kryos.get().writeObject(output, data);
return output.toBytes();
}
Try this i think this will work..
Upvotes: 1