我是akka http的新手,我在编组和解组case类时遇到了困难,这是我的代码
case class Event(uuid:String)
//main class
class demo {
val route: Route =
post {
path("create-event") {
entity(as[Event]) { event =>
complete("event created")
}
}
}
}
}
我在这一行得到一个编译时错误
entity(as[Event]) { event =>
could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[models.event.Event]
2条答案
按热度按时间m0rkklqb1#
有一个简单的方法可以解决这个问题。akka-http-Jackson有一个请求解组器的实现。
sbt添加库:
然后在代码中
nwo49xxi2#
默认情况下,Akka-Http使用spray对json进行封送和解送,错误是因为没有定义用于转换的隐式转换器。
akka-http documentation中提供了详细步骤
希望对你有帮助!!