Scala compile time error: No implicits found for parameter evidence$2: BodyWritable[Map[String, Object]]

Scala compile time error: No implicits found for parameter evidence$2: BodyWritable[Map[String, Object]]

我正在开发 scala play 框架应用程序。我正在尝试调用 Web 服务 API,它采用如下请求有效负载数据

{
    "toID": [
        "email1@email.com",
        "email2@email.com"
    ],
    "fromID": "info@test.com",
    "userID": "ervd12fdsfksdjnfn9832rbjfdsnf",
    "mailContent": "Dear Sir, ..."
}

为此,我使用以下代码

ws.url(Utils.messengerServiceUrl + "service/email")
          .post(
            Map("userID" -> userID, "mailContent" -> userData.message, "fromID" -> "info@test.com", "toID" -> userData.emails)).map { response =>
          println(response.body, response.status)
        }

所以对于这段代码,编译器抱怨 "toID" -> userData.emailsNo implicits found for parameter evidence$2: BodyWritable[Map[String, Object]]

所以我的问题是如何使用 WSClient 发送此类数据?

你可以用 case class 那样做

import play.api.libs.json._


case class Message(toID: Seq[String], fromID: String, userID: String, mailContent: String)

object Message {
  implicit val writes: Writes[Message] = Json.writes[Message]
}

注意object Messageimplicit writes

的定义