kryo: Java8 Lambdas cannot be deserialized
Deserializing Java8 lambdas fails with ClassNotFoundException: Test$$Lambda$1/1279149968
Example:
private <T> T kryoSerDeser(T r) throws IOException, ClassNotFoundException {
Kryo kryo = new Kryo();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (Output output = new Output(baos)) {
kryo.writeClassAndObject(output, r);
}
try (Input input = new Input((new ByteArrayInputStream(baos.toByteArray())))) {
return (T) kryo.readClassAndObject(input);
}
}
@Test
public void testLambdaInKryo() throws IOException, ClassNotFoundException {
Runnable r = () -> System.out.println("works");
kryoSerDeser(r).run();
}
Using Java’s standard ObjectOutput/Input streams on lambdas implementing Serializable interface works fine.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 34 (2 by maintainers)
Commits related to this issue
- Add support for serialization of Java8 closures (see #215). — committed to EsotericSoftware/kryo by romix 10 years ago
- Make Closure public, moving it to ClosureSerializer. Closure is moved to ClosureSerializer because it's tightly coupled and this makes the connection more obvious. This also renames `Kryo.isClousre`... — committed to magro/kryo by magro 8 years ago
- Make Closure public, moving it to ClosureSerializer. Closure is moved to ClosureSerializer because it's tightly coupled and this makes the connection more obvious. This also renames `Kryo.isClousre`... — committed to magro/kryo by magro 8 years ago
+1. Please, provide a full example for serializing/deserializing a lambda on the main page.