接受来自请求 AKKA-HTTP 的所有 JSON

问题描述

我有一条路线:

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

他使用案例类:

// 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])

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...