Reputation: 11
I'm using Kryo 5.6.0 with java 1.8, While serializing with class registration getting below Exception
com.esotericsoftware.kryo.KryoException: java.lang.IllegalArgumentException: Class is not registered: java.util.Collections$UnmodifiableMap Note: To register this class use: kryo.register(java.util.Collections.UnmodifiableMap.class);
Tried this kryo.register(java.util.Collections.UnmodifiableMap.class)
but the problem here is UnmodifiableMap is not visible to add while registering, If we add we will get classNotFoundException. How to overcome this scenario
my Class
public class TestClass implements Serializable {
private static final long serialVersionUID = 6400867639765519428L;
private List<Books> items;
public TestClass(List<Books> items) {
super();
if (items != null) {
for (Book item : items) {
item.setOwner(this);
}
this.items = Collections.unmodifiableList(items);
}
}
public List<Books> getItems() {
return items;
}
}
Kryo changes
public class HelloKryo {
public static void main (String[] args) throws Exception {
Kryo kryo = new Kryo();
kryo.register(TestClass.class);
kryo.register(Books.class);
kryo.register(List.class);
Output output = new Output();
kryo.writeClassAndObject(output, object)
byte[] result = output.toBytes();
}
}
Upvotes: 1
Views: 111