[英]spray-json: could not find implicit value for FromRequestUnmarshallar
I'm creating my first application with AKKA-http. 我正在用AKKA-http创建我的第一个应用程序。 I'm currently using spray-json to write object to json.
我目前正在使用spray-json将对象写入json。 When I created GET request everything is working fine, but I tried a POST request and the following error shows:
当我创建GET请求时,一切正常,但是我尝试了POST请求,并显示以下错误:
Error:(55, 26) could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[nl.quintor.model.Employee]
entity(as[Employee]) { request =>
This is my main class: 这是我的主要课程:
object Main extends App with Routes {
implicit val system = ActorSystem("system")
implicit val executor: ExecutionContext = system.dispatcher
implicit val materializer: ActorMaterializer = ActorMaterializer()
override val slickboard = createSlickboard
Http().bindAndHandle(routes, httpInterface, httpPort)
private def createSlickboard: ActorRef =
system.actorOf(Slickboard.props(system), applicationName)
}
}
I defined my routes in the following trait: 我用以下特征定义了路线:
trait Routes extends CORSSupport with Protocols {
val slickboard: ActorRef
implicit val timeout = Timeout(5 seconds)
val routes =
corsHandler {
pathPrefix("employees") {
pathEnd {
get {
complete {
(slickboard ? GetAllEmployees).mapTo[HttpResponse]
}
}
}
} ~
pathPrefix("employee") {
path(IntNumber) { id =>
get {
complete {
(slickboard ? GetEmployeeById(id)).mapTo[HttpResponse]
}
} ~
post {
decodeRequest {
entity(as[Employee]) { request =>
complete {
request.toString()
}
}
}
}
}
}
}
}
I defined my protocol just like spray recommended: 我定义了协议,就像Spray建议一样:
trait Protocols extends DefaultJsonProtocol {
implicit val employeeFormat = jsonFormat8(Employee.apply)
}
The class I'm trying to convert to json is the following: 我要转换为json的类如下:
case class Employee(ID: Int, firstname: String, lastname: String, street: String, zipCode: String, city: String, phoneNumber: String, image: String)
I tried multiple solutions found in stack overflow, but none of them are actually working. 我尝试了在堆栈溢出中找到的多个解决方案,但实际上都没有。
Could someone please help me with this problem? 有人可以帮我解决这个问题吗?
我怀疑你需要
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.