Apache pekko ( akka http ) - 从请求中提取的字符串正文没有引号

问题描述 投票:0回答:1

我正在为我的下一个项目 POCing pekko http ( akka http )。 我从请求主体实体中提取了 json 字符串,但它没有字符串值的引号。

路由 dsl 上的代码片段:

  post {
    path("account") {
      extract(_.request) { request =>
        val body = Await.result(request.entity.toStrict(1.second).map(_.data.utf8String), 1.second)
        println(body)
        complete(...)
      }
    }
  }

请求:curl -X POST http://localhost:9090/account -d '{"account":{"name":"TESTE"}}'
提取的 json 字符串:{account:{name:TESTE}}

有人知道如何在不删除引号的情况下提取请求正文实体吗?

json request akka-http
1个回答
0
投票

这会提取原始 JSON 字符串而不删除引号:

  val jsonRaw: Route =
  path("jsonRaw")(
    post(
      entity(as[String]) {
        json =>
          println("JSON raw: " + json)
          complete(StatusCodes.OK)
      }
    )
  )
© www.soinside.com 2019 - 2024. All rights reserved.