简体   繁体   English

spray-json错误:无法找到参数um的隐含值

[英]spray-json error: could not find implicit value for parameter um

I have this case class 我有这个案例课

case class Person(val name: String)

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

I'm trying spray-json in order to parse post request: 我正在尝试使用spray-json来解析post请求:

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

However I get when I try to compile this: 但是当我尝试编译时,我得到了:

src/main/scala/com/example/ServiceActor.scala:61: error: could not find implicit value for parameter um: spray.httpx.unmarshalling.FromRequestUnmarshaller[com.example.Person] src / main / scala / com / example / ServiceActor.scala:61:错误:找不到参数um的隐式值:spray.httpx.unmarshalling.FromRequestUnmarshaller [com.example.Person]

I don't understand what's happening, how can I fix this to be working? 我不明白发生了什么,我怎么能解决这个问题呢?

thanks 谢谢

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. Spray的'entity [E]'指令在其类型E的范围内需要隐式编组器JsonImplicits对象为类型E创建json marshaller和unmarshaller。

You need to make sure that implicit val impPerson is in the scope, in other words put import JsonImplicits._ above the route definition. 您需要确保implicit val impPerson在范围内,换句话说,将import JsonImplicits._放在路由定义之上。

package abc.json

import spray.json.DefaultJsonProtocol


object OrderJsonProtocol extends DefaultJsonProtocol {

  implicit val orderFormat = jsonFormat1(Order)
}


case class Order(orderNumber: String)

import akka.actor.Actor
import abc.json._
import spray.routing.HttpService

class OrderRestServiceActor extends Actor with HttpService {

  def actorRefFactory = context

  def receive = runRoute(route)



  val route = {
    import OrderJsonProtocol._
    import spray.httpx.SprayJsonSupport.sprayJsonUnmarshaller


    path("order") {
      post {
        println("inside the path")
        entity(as[Order]) { order =>
         complete(s"OrderNumber: ${order.orderNumber}")
        }

      }
    }

  }

}

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

相关问题 spray-json递归json问题-找不到证据参数的隐式值 - spray-json recursive json issue - could not find implicit value for evidence parameter spray-json:找不到FromRequestUnmarshallar的隐式值 - spray-json: could not find implicit value for FromRequestUnmarshallar play-json-找不到参数um的隐式值 - play-json - Could not find implicit value for parameter um 找不到参数 um 的隐式值 - Could not find implicit value for parameter um 使用spray.json序列化多态类获取无法找到类型为证据的隐式值 - serializing polymorphic classes using spray.json getting could not find implicit value for evidence parameter of type spray-json-发散的隐式扩展 - spray-json - diverging implicit expansion Spray,ScalaTest和HTTP服务:找不到参数ta的隐式值: - Spray, ScalaTest and HTTP services: could not find implicit value for parameter ta: 找不到参数编组器的隐式值:spray.httpx.marshalling.ToResponseMarshaller [Unit] - could not find implicit value for parameter marshaller: spray.httpx.marshalling.ToResponseMarshaller[Unit] 找不到参数marshaller的隐含值:spray.httpx.marshalling.ToResponseMarshaller - could not find implicit value for parameter marshaller: spray.httpx.marshalling.ToResponseMarshaller Scala错误无法找到参数的隐式值 - Scala error Could not find implicit value for parameter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM