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

Most upvoted comments

+1. Please, provide a full example for serializing/deserializing a lambda on the main page.