1
私は次のようにアッカのhttpクエリのparamをアンマーシャリングしたいと思います:akka http - LocalDateとしてクエリパラメータをアンマーシャリングする方法は?
name=jim&age=30&dob=11-20-1990
import java.time.LocalDate
import akka.http.scaladsl.marshalling.ToResponseMarshallable
import akka.http.scaladsl.server._
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.headers.RawHeader
import akka.http.scaladsl.server.Directives.{complete, _}
...
parameters(('name.as[String].?, 'age.as[Int].?, 'dob.as[String].?)) { (name, age, dob) =>
私は、文字列またはintとしてOKすべてをアンマーシャリングすることができますが、私はjava.utilのようDOBをunmarsallしたいと思います。
parameters(('name.as[String].?, 'age.as[Int].?, 'dob.as[LocalDate].?)) { (name, age, dob) =>
しかし、私は次のエラーを取得しています:
[error] routes/Router.scala:141: type mismatch;
[error] found : (akka.http.scaladsl.common.NameOptionReceptacle[Int], akka.http.scaladsl.common.NameOptionReceptacle[Int], akka.http.scaladsl.common.NameOptionReceptacle[java.time.LocalDate])
[error] required: akka.http.scaladsl.server.directives.ParameterDirectives.ParamMagnet
[error] parameters(('$top.as[Int].?, '$skip.as[Int].?, 'modified_date.as[LocalDate].?)) { (top, skip, modifiedDate) =>
私はスコープでカスタムLOCALDATEのアンマーシャラーを追加しようとしたが、私はまだのgettinよ、このようなLOCALDATE、グラム同じエラー:
implicit val LocalDateUnmarshaller = new JsonReader[LocalDate] {
def read(value: JsValue) = value match {
case JsString(x) => LocalDate.parse(x)
case x => throw new RuntimeException(s"Unexpected type %s on parsing of LocalDate type".format(x.getClass.getName))
}
}
おかげで、これは、重複しました – Rory