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

五迷三道 提交于 2020-12-15 04:28:10

问题


I am working on scala play framework application. I am trying to call a web service API which takes request payload data as follows

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

And for this I am using following code

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)
        }

So for this code, compiler is complaining about "toID" -> userData.emails saying No implicits found for parameter evidence$2: BodyWritable[Map[String, Object]]

So my question is how to send such data using WSClient?


回答1:


You can do it with case class like that

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]
}

Pay attention to the definition of the object Message with implicit writes



来源:https://stackoverflow.com/questions/59102698/scala-compile-time-error-no-implicits-found-for-parameter-evidence2-bodywrita

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!