akka/akka-http

Java DSL: Marshaller not usable to easily create HttpRequests

开放

#2,128 创建于 2018年7月26日

 (0 条评论) (1 个反应) (0 位负责人)Scala (598 个派生)batch import
1 - triagedhelp wantedt:core

仓库指标

星标
 (1,311 个星标)
PR 合并指标
 (平均合并 1天 10小时) (30 天内合并 2 个 PR)

描述

Goes hand in hand with the fact that we don't really provide a high level user API for the http client.

Something among the lines of

class Marshaller[-A, +B] private (implicit val asScala: marshalling.Marshaller[A, B]) {
  import Marshaller.fromScala

  /** INTERNAL API: involves unsafe cast (however is very fast) */
  // TODO would be nice to not need this special case
  @InternalApi
  private[akka] def asScalaCastOutput[C]: marshalling.Marshaller[A, C] = asScala.asInstanceOf[marshalling.Marshaller[A, C]]

  def map[C](f: function.Function[B @uncheckedVariance, C]): Marshaller[A, C] = fromScala(asScala.map(f.apply))

  def compose[C](f: function.Function[C, A @uncheckedVariance]): Marshaller[C, B] = fromScala(asScala.compose(f.apply))

  // new 
  def marshal(value: A, system: ActorSystem) =
    marshal(value, system.dispatcher)

  // new 
  def marshal(value: A, dispatcher: ExecutionContext): CompletionStage[util.List[Marshalling[B]]] = {
    import scala.collection.JavaConverters._
    import scala.compat.java8.FutureConverters._
    val res: Future[List[Marshalling[B]]] = asScala.apply(value)(dispatcher)
    res.map(_.asJava)(dispatcher).toJava
  }

}

could be a start...

贡献者指南