score:1

Accepted answer

As is: WebSocket.acceptOrResult[JsValue, JsValue] you expect your websocket to receive JsValue.

This seems to match you code below in MessageActor:

override def receive = {
  case message: JsValue => // ...
}

However, you shouldn't expect the conversion from JsValue to WSMessageIn to happen without your intervention.

What you could do is simply:

override def receive = {
  case message: JsValue =>
    WSMessageIn.json2object(message) match {
      case message: PostMessage =>
        ...
      case message: MessageFromIn =>
        ...
    }
}

You were probably expecting an implicitly conversion, you can get it by giving a hint to the compiler (i.e., saying what you expect):

override def receive = {
  case message: JsValue =>
    (message: WSMessageIn) match {
      case message: PostMessage =>
        ...
      case message: MessageFromIn =>
        ...
    }
}

Note: you could turn abstract class WSMessageIn() into: sealed trait WSMessageIn


Related Query

More Query from same tag