接受请求 AKKA-HTTP 中的所有 JSON

Accept all JSON from the request AKKA-HTTTP

我有一条路线:

val receiveMessage = post {
  path("receive_message"){
    entity(as[Receive]) {
      message => {
        println(message)
        complete("ok")
      }
    }
  }
}

他处理案例class:

// spray (JSON marshalling)
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
import spray.json.DefaultJsonProtocol._

    final case class Receive(notification_text: String)
    // formats for unmarshalling and marshalling
    implicit val itemFormat4 = jsonFormat1(Receive)

有没有办法创建一条可以接收任何 JSON 个对象的路由?

您可以输入路线以接收 JsObject(来自 SprayJson):

entity(as[JsObject])