While trying to persist an Event and update the state of my actor, I get this exception:
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `module.MyActor$State`: non-static inner classes like this can only by instantiated using default, no-argument constructor
Here is how my actor case class looks like:
object MyActor {
final case class Settings(
name: String = "",
accessToken: AccessToken = AccessToken()
) extends CborSerializable
.
.
.
}
class MyActor()(implicit system: ActorSystem[_]) {
import MyActor._
private implicit val executionContext: ExecutionContextExecutor = system.executionContext
private val sharding = ClusterSharding(system)
// State
final case class State(
settings: Settings = Settings(),
pollTime: Long = 0L
) extends CborSerializable
.
.
private def onEvent(state: State, event: Event): State = {
event match {
case _ => {
state.copy(pollTime = state.pollTime.updated(timestampToStringDate(System.currentTimeMillis())))
}
}
.
.
}
This is a typed EventSourced Actor, The Event/Command handlers are omitted here since the issue is wrt to serialization.
I am using jackson serializer and have updated that in my application.conf
akka.actor.serialization-bindings {
"module.CborSerializable" = jackson-cbor
}
I defined a trait CborSerializable
in my module.
I wanted to understand what am I doing wrong here.