akka/akka-http

Java DSL: Marshaller not usable to easily create HttpRequests

Aperta

#2128 aperta il 26 lug 2018

 (0 commenti) (1 reazione) (0 assegnatari)Scala (598 fork)batch import
1 - triagedhelp wantedt:core

Metriche repository

Star
 (1311 stelle)
Metriche merge PR
 (Merge medio 1g 10h) (2 PR mergiate in 30 g)

Descrizione

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...

Guida contributor