0

Using Akka persistence I get this exception:

Caused by: akka.persistence.typed.internal.JournalFailureException: Exception during recovery. Last known sequence number [0]. PersistenceId [PersistenceExample], due to: Cannot construct instance of com.exercisePersistence.simpleExample.MyPersistentBehavior$Added (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (byte[])"{"data":"data1"}"; line: 1, column: 2] at akka.persistence.typed.internal.ReplayingEvents.onRecoveryFailure(ReplayingEvents.scala:221) at akka.persistence.typed.internal.ReplayingEvents.onJournalResponse(ReplayingEvents.scala:143) ... 26 common frames omitted

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of com.exercisePersistence.simpleExample.MyPersistentBehavior$Added (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (byte[])"{"data":"data1"}"; line: 1, column: 2]

The class Added that give me exception is:

public class MyPersistentBehavior 
    extends EventSourcedBehavior<MyPersistentBehavior.Command, 
        MyPersistentBehavior.Event, MyPersistentBehavior.State> {

    // COMMAND
    interface Command {}
    public static class Add implements Command {
      public final String data;

      public Add(String data) {
        this.data = data;
      }
    }
...
}

File reference.conf

akka {
 actor {
serializers {
  jackson-json = "akka.serialization.jackson.JacksonJsonSerializer"
  jackson-cbor = "akka.serialization.jackson.JacksonCborSerializer"
  proto = "akka.remote.serialization.ProtobufSerializer"
}
serialization-bindings {
  "com.exercisePersistence.simpleExample.MyPersistentBehavior" = jackson-json
  "com.exercisePersistence.simpleExample.MyPersistentBehavior$Added" = jackson-json
  #"docs.serialization.CborSerializable" = jackson-cbor
  "com.google.protobuf.Message" = proto
}

}

akka.serialization.jackson {
      jackson-json-message {
        serialization-features {
          WRITE_DATES_AS_TIMESTAMPS = on
        }
      }
      jackson-json-event {
        serialization-features {
          WRITE_DATES_AS_TIMESTAMPS = off
        }
      }
  }
  persistence {
    journal {
      plugin = "leveldb"

      leveldb {
        dir = "target/persistence/journal"
      }
    }

    snapshot-store.local.dir = "target/persistence/snapshots"
  }
}

leveldb {
  dir = "target/persistence/journal"
  checksum: "off"
  class: "akka.persistence.journal.leveldb.LeveldbJournal"
  dir: "target/persistence/journal"
  fsync: "on"
  native: "on"
  plugin-dispatcher : "akka.persistence.dispatchers.default-plugin-dispatcher"
  replay-dispatcher : "akka.persistence.dispatchers.default-replay-dispatcher"
}

If want to clone the project this is the Github link: https://github.com/Mazzotta13/AkkaTutorial.git

AM13
  • 661
  • 1
  • 8
  • 18

1 Answers1

0

You have a couple different options:

  1. Since you're serializing with Jackson you can add @JsonCreator annotation to your constructor in protocol objects.
  2. You can use Lombak to create your protocol objects which saves on a lot of java boiler plate and annotate it with @NoArgsConstructor.
  3. Create an empty constructor.

Some information on it can be found here, https://doc.akka.io/docs/akka/current/serialization-jackson.html#annotations