简体   繁体   English

Scala 编译时错误:未找到参数证据 $2 的隐式:BodyWritable[Map[String, Object]]

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

I am working on scala play framework application.我正在开发 Scala Play 框架应用程序。 I am trying to call a web service API which takes request payload data as follows我正在尝试调用一个 Web 服务 API,它接受请求有效负载数据,如下所示

{
    "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]]所以对于这段代码,编译器抱怨“toID”-> userData.emails没有找到参数证据 $2 的隐式:BodyWritable[Map[String, Object]]

So my question is how to send such data using WSClient?所以我的问题是如何使用 WSClient 发送此类数据?

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注意implicit writesobject Message的定义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java Stream-编译时错误-类型不匹配:无法从Map转换 <Object,Object> 到地图 <Integer,List<String> &gt; - Java Stream - Compile time Error - Type mismatch: cannot convert from Map<Object,Object> to Map<Integer,List<String>> Java 最终字符串参数未标记为 lambda 表达式中的编译时错误 - Java final string parameter is not marked as compile time error in lambda expression 关于Map中的编译时间错误 - Regarding compile time error in Map 如何在编译时跳过此通用 object 错误 - How to skip this generic object error in compile time 播放Scala编译错误 - Play Scala Compile Error 泛型:为什么要传递列表 <String> 而不是列表 <Object> 给出编译时错误 - Generics: Why passing List<String> instead of List<Object> gives compile time error T ...(泛型vararg参数)在编译时真的被剥离到Object []吗? - Is T… (generics vararg parameter) really stripped down to Object[] at compile time? 如果传递给method的字符串参数有@deprecated注释,则在编译时检查 - check at compile time if string parameter passed to method has @deprecated annotation 将vararg参数传递给Kotlin中的另一个函数时编译时间错误 - Compile time error in passing vararg parameter to another function in Kotlin Java RMI教程编译时错误-找不到接口 - Java RMI tutorial compile time error - Interface not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM