spray-json错误:找不到参数um的隐式值 [英] spray-json error: could not find implicit value for parameter um

查看:166
本文介绍了spray-json错误:找不到参数um的隐式值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个案例类

case class Person(val name: String)

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

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

I'm trying spray-json in order to parse post request:

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

但是我得到了当我尝试编译此代码时:

However I get when I try to compile this:


src / main / scala / com / example / ServiceActor.scala:61:错误:无法
查找参数um的隐式值:
spray.httpx.unmarshalling.FromRequestUnmarshaller [com.example.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]

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

I don't understand what's happening, how can I fix this to be working?

谢谢

推荐答案

Spray的'entity [E]'指令要求在其范围内为E类型隐式封送处理程序。
JsonImplicits 对象创建json封送处理程序

Spray's 'entity[E]' directive requires implicit marshaller in its scope for the type E. JsonImplicits object creates json marshaller and unmarshaller for the type E.

您需要确保 implicit val impPerson 在范围内,在换句话说,将 import JsonImplicits ._ 放在路由定义上方。

You need to make sure that implicit val impPerson is in the scope, in other words put import JsonImplicits._ above the route definition.

这篇关于spray-json错误:找不到参数um的隐式值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆