Hello All,
I'm trying to use Kryo to serialize data from an existing application.
I have some problems as this data has java.util.List which may have been created with Arrays.asList(T...a), and it does return a java.util.Arrays.ArrayList (note it is not java.util.ArrayList) and it does not work using the FieldSerializer...
How can I manage these classes with Kryo?
Can I force Kryo to use java.util.ArrayList instead of java.util.Arrays.ArrayList in some way?
Thank you for your support!
Cristiano
PS: Here a simple JUnit test that capture the essence of my problem:
public class TestKryoArrays {
public static class MyData {
public List<String> value;
}
@Test
public void testMydata() {
MyData original = new MyData();
original.value = Arrays.asList("one", "two", "three");
Kryo kryo = new Kryo();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Output output = new Output(bos);
kryo.writeObject(output, original);
output.close();
byte[] outBytes = bos.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(outBytes);
Input input = new Input(bis);
MyData processed = kryo.readObject(input, MyData.class); // throw KryoException!!! see below
input.close();
assertEquals(3, processed.value.size());
assertEquals(original.value.get(0), processed.value.get(0));
assertEquals(original.value.get(1), processed.value.get(1));
assertEquals(original.value.get(2), processed.value.get(2));
}
}
==>
com.esotericsoftware.kryo.KryoException: Class cannot be created (missing no-arg constructor): java.util.Arrays$ArrayList
Serialization trace:
value (com.thalesgroup.it.aocc.camel.TestKryoArrays$MyData)
at com.esotericsoftware.kryo.Kryo.newInstantiator(Kryo.java:1050)
at com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:1062)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.create(CollectionSerializer.java:82)
...