簡體   English   中英

在Scala中使用Finagle / Finch在體內發送數據時出現錯誤

[英]Errors when sending data in body using Finagle/Finch in Scala

我正在使用Finagle / Finch ,但出現此錯誤:

diverging implicit expansion for type argonaut.DecodeJson[A] starting 
  with method MapDecodeJson in trait DecodeJsons
diverging implicit expansion for type argonaut.DecodeJson[V] starting 
  with method MapDecodeJson in trait DecodeJsons
not enough arguments for method body: (implicit d: 
 io.finch.Decode.Aux[A,CT], implicit ct: 
 scala.reflect.ClassTag[A])io.finch.Endpoint[A]. Unspecified value 
 parameters d, ct.

對於此代碼:

def sendPost(db: CommDb): Endpoint[String] =
  post("posts" :: body.as[String]) { s: String =>
    Ok("success")
  }

我不知道該如何解決。

body API在Finch 0.11中進行了更改。 只需將您的body調用更改為body[CT, Foo] (其中CT是內容類型),就應該對其進行編譯。 一件事: String主體是一種特殊情況,因此您可能要使用stringBody (無類型參數),因為body傾向於使用給定的JSON / XML /任何解碼器解碼有效負載。

scala> import io.finch._, io.finch.circe._

scala> s(Input.post("/").withBody[Application.Json](Map("foo" -> "bar"))).awaitValueUnsafe()
res2: Option[String] = Some({"foo":"bar"})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM