加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – spray-json错误:找不到参数um的隐式值

发布时间:2020-12-16 18:57:22 所属栏目:安全 来源:网络整理
导读:我有这个案例类 case class Person(val name: String)object JsonImplicits extends DefaultJsonProtocol { implicit val impPerson = jsonFormat1(Person)} 我正在尝试spray-json以解析发布请求: post { entity(as[Person]) { person = complete(person) }
我有这个案例类

case class Person(val name: String)

object JsonImplicits extends DefaultJsonProtocol {
  implicit val impPerson = jsonFormat1(Person)
}

我正在尝试spray-json以解析发布请求:

post {
    entity(as[Person]) { person =>
      complete(person)
    }
  }

但是当我尝试编译这个时,我得到了

src/main/scala/com/example/ServiceActor.scala:61: error: could not
find implicit value for parameter um:
spray.httpx.unmarshalling.FromRequestUnmarshaller[com.example.Person]

我不明白发生了什么,我该如何解决这个问题呢?

谢谢

解决方法

Spray的“实体[E]”指令在E类的范围内需要隐式编组.
JsonImplicits对象为类型E创建json marshaller和unmarshaller.

您需要确保隐式val impPerson在范围内,换句话说,将导入JsonImplicits._放在路由定义之上.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读