diff options
author | vlad <vlad@driver.xyz> | 2017-02-28 22:22:39 -0800 |
---|---|---|
committer | vlad <vlad@driver.xyz> | 2017-02-28 22:22:39 -0800 |
commit | ca1abf1103139da68c1c2e938636d1d7d03b6b01 (patch) | |
tree | cc5bb16216a0344aa7f514d18bbeaece1243f9e5 /src | |
parent | dce20b0096c909a6c53a4403e68eeb8c95efcab4 (diff) | |
download | driver-core-0.10.21.tar.gz driver-core-0.10.21.tar.bz2 driver-core-0.10.21.zip |
Nice utils to implement rest services. Unmarshallingv0.10.21
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/xyz/driver/core/rest.scala | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/main/scala/xyz/driver/core/rest.scala b/src/main/scala/xyz/driver/core/rest.scala index db54f97..b250ac9 100644 --- a/src/main/scala/xyz/driver/core/rest.scala +++ b/src/main/scala/xyz/driver/core/rest.scala @@ -143,18 +143,19 @@ object rest { protected implicit val materializer: ActorMaterializer implicit class ResponseEntityFoldable(entity: Unmarshal[ResponseEntity]) { - def fold[T](default: => T)(implicit um: Unmarshaller[ResponseEntity, T]): Future[T] = { - if (entity.value.isKnownEmpty()) Future.successful[T](default) else entity.to[T](um, exec, materializer) - } + def fold[T](default: => T)(implicit um: Unmarshaller[ResponseEntity, T]): Future[T] = + if (entity.value.isKnownEmpty()) Future.successful[T](default) else entity.to[T] } protected def unitResponse(request: Future[Unmarshal[ResponseEntity]]): OptionT[Future, Unit] = OptionT[Future, Unit](request.flatMap(_.to[JsValue]).map(_ => Option(()))) - protected def optionalResponse[T: RootJsonFormat](request: Future[Unmarshal[ResponseEntity]]): OptionT[Future, T] = + protected def optionalResponse[T](request: Future[Unmarshal[ResponseEntity]])( + implicit um: Unmarshaller[ResponseEntity, Option[T]]): OptionT[Future, T] = OptionT[Future, T](request.flatMap(_.fold(Option.empty[T]))) - protected def listResponse[T: RootJsonFormat](request: Future[Unmarshal[ResponseEntity]]): ListT[Future, T] = + protected def listResponse[T](request: Future[Unmarshal[ResponseEntity]])( + implicit um: Unmarshaller[ResponseEntity, List[T]]): ListT[Future, T] = ListT[Future, T](request.flatMap(_.fold(List.empty[T]))) protected def jsonEntity(json: JsValue): RequestEntity = |