2
我噴JSON支持發現隱含的價值看起來像這樣阿卡-HTTP:無法爲參數解組
object MarshallingSupport extends SprayJsonSupport {
implicit def json4sFormats: Formats = DefaultFormats
}
而在我的路線我想請求映射到DTO
object Main extends App with AppConfig with BaseService with MainActorSystem {
val processor = system.actorOf(Props(), "processorActor")
val view = system.actorOf(Props(), "processorActor")
override protected implicit val executor: ExecutionContext = system.dispatcher
override protected val log: LoggingAdapter = Logging(system, getClass)
override protected implicit val materializer: ActorMaterializer = ActorMaterializer()
Http().bindAndHandle(routes(processor, view), httpInterface, httpPort)
}
trait BaseServiceRoute {
protected implicit def executor: ExecutionContext
protected implicit def materializer: ActorMaterializer
protected def log: LoggingAdapter
}
trait MainActorSystem {
implicit val system = ActorSystem("booking")
}
final case class CalculatePriceForRangeDto(unitId: Int, from: Long, to: Long)
trait PriceServiceRoute extends BaseServiceRoute {
implicit val timeout = Timeout(30 seconds)
import com.example.crudapi.utils.MarshallingSupport._
def customersRoute(command: ActorRef, query: ActorRef) = pathPrefix("price") {
post {
path("calculate") {
decodeRequest {
entity(as[CalculatePriceForRangeDto]) {
priceForRange => onComplete((query ? CalculatePriceForRange(
但我越來越
Error:(32, 20) could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[com.example.crudapi.http.routes.CalculatePriceForRangeDto]
entity(as[CalculatePriceForRangeDto]) {
^
已經看到所有相關的SO問題,但沒有解決我的問題。奇怪的部分是,我試過Typesafe模板akka-dddd-cqrs,它的工作原理,相同的代碼。
我是否缺少隱式上下文? 任何想法可能是什麼?
什麼樣的類是DigestItemWire?沒有在範圍內。 – Reeebuuk
@Reeebuuk這就是您想要序列化/反序列化的案例類的例子,就像您的案例中的「CalculatePriceForRangeDto」一樣。 – expert
試過,但我得到錯誤:類型不匹配; found:(Int,Long,Long)=> com.example.crudapi.http.routes.CalculatePriceForRangeDto required:(?,?,?,?,?,?)=>? 注:內含價值CalculatePriceForRangeDtoFormat這裏不適用,因爲它是應用點之後,並沒有一個明確的結果類型 隱含VAL CalculatePriceForRangeDtoFormat = jsonFormat6(CalculatePriceForRangeDto.apply) – Reeebuuk