0
我试图将JSON i/p映射到我的案例类CacheRequest。
请求是POST。
我是新来的斯卡拉和阿卡。
使用json4s处理POST请求中的JSON数据
import org.json4s.{DefaultFormats, Formats}
implicit val formats: Formats = DefaultFormats
val route: Route = traceContextAwareRoute {
pathPrefix(system.name) {
post {
path("sample") {
entity(as[CacheRequest]) { x => {
val cacheRequest: CacheRequest = CacheRequest(x.a, x.b, x.c, x.d, x.e, x.f)
onComplete(getSystemStock(cacheRequest)) {
(response: Try[Option[CacheResponse]]) => complete(processResponse(response))
}
}
}
}
}
}
我的情况下类是这样的。
case class CacheRequest(a: String,
b: String,
c: Int,
d: Int,
e: Int,
f: Int)
获得这样的错误
could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[mcc.movie.common.model.CacheRequest]
not enough arguments for method as: (implicit um: akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[mcc.movie.common.model.CacheRequest])akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[mcc.movie.common.model.CacheRequest]
I'supposed做到这一点使用json4s。
有关这方面的任何帮助对我来说都很好。
我补充说,依赖 “de.heikoseeberger” %% “阿卡-HTTP-瑟茜” % “1.12.0” 。但是,当导入 - >导入de.heikoseeberger.akkahttpjson4s.Json4sSupport时,我得到“无法解析akkahttpjson4s”。 –
添加此:“de.heikoseeberger”%%“akka-http-json4s”%“1.12.0”, –
是的,它的工作。谢谢。 –