Re: [akka-user] Spray-json support and FromResponseUnmarshaller

2016-04-24 Thread Konrad Malawski
Hi there,
the Unmarshaller type you wrote is correct, however the infrastructure is async 
in any case – inside withMaterialized you return a Future.

implicit val um: Unmarshaller[Future[String], String] = ???
val eventualString: Future[String] = Unmarshal(Future("")).to[String](um, 
system.dispatcher, materializer)
For Future[X] => X there must be either:
  - a callback (map / onComplete etc) or:
  - blocking involved
no way around that.

Hope this helps.

-- 
Konrad `ktoso` Malawski
Akka @ Lightbend

On 23 April 2016 at 15:04:25, Edmondo Porcu (edmondo.po...@gottexbrokers.com) 
wrote:

Unmarshaller[Future[A],B] 

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Spray-json support and FromResponseUnmarshaller

2016-04-23 Thread Edmondo Porcu
I am not sure I understood, would this be blocking? 

implicit def liftUnmarshaller[A,B](implicit unmarshaller:Unmarshaller[A,B]):

Unmarshaller[Future[A],B] = Unmarshaller.withMaterializer(
  ec => m => a => a.flatMap{ x =>
unmarshaller.apply(x)(ec,m)
  }(ec)
)



Il giorno venerdì 22 aprile 2016 12:01:15 UTC+1, loe...@posteo.de ha 
scritto:
>
> > On 22 Apr 2016, at 12:11, Edmondo Porcu  > wrote: 
> > 
> > Shouldn't be possible to lift the unmarshaller with an implicit 
> conversion? 
>
> How? Do you want to block? 
>
> Heiko 
>
>

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Spray-json support and FromResponseUnmarshaller

2016-04-22 Thread loempl
> On 22 Apr 2016, at 12:11, Edmondo Porcu  
> wrote:
> 
> Shouldn't be possible to lift the unmarshaller with an implicit conversion?

How? Do you want to block?

Heiko

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Spray-json support and FromResponseUnmarshaller

2016-04-22 Thread Edmondo Porcu
Shouldn't be possible to lift the unmarshaller with an implicit conversion?

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Spray-json support and FromResponseUnmarshaller

2016-04-20 Thread loempl
Edmondo,

You can’t expect unmarshalling to magically unfold the Future you get back. 
Hence you have to map. Or, to be more precise, you have to flatMap, because 
unmarshalling returns another Future.

```
responseFuture.flatMap(Unmarshal(_).to[MyClass]) // Notice that you’re still in 
Future land
```

--

Heiko Seeberger
Home: heikoseeberger.de 
Twitter: @hseeberger 
Public key: keybase.io/hseeberger 
> On 21 Apr 2016, at 00:02, Edmondo Porcu  
> wrote:
> 
> Hello,
> 
> I am using Spray-json support and I have correctly implemented my json 
> protocol by providing implicit RootJsonFormat. Are there available (implicit) 
> conversions to
> 
> -  lift the FromEntityUnmarshaller[MyClass] provided by Spray Json into a 
> FromResponseUnmarshaller[MyClass] 
> 
> -  lift a Unmarshaller[HttpResponse,MyClass] into an 
> Unmarshaller[Future[HttpResponse],MyClass]? 
> 
> Obviously the following code doesn't compile:
> 
>   val responseFuture: Future[HttpResponse] = 
> Http().singleRequest(HttpRequest(uri = "/bah"))
>   val response = Unmarshal(responseFuture).to[MyClass]
> 
> 
> Thank you for your help
> 
> Edmondo
> 
> 
> -- 
> >> Read the docs: http://akka.io/docs/ 
> >> Check the FAQ: 
> >> http://doc.akka.io/docs/akka/current/additional/faq.html 
> >> 
> >> Search the archives: https://groups.google.com/group/akka-user 
> >> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to akka-user+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to akka-user@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/akka-user 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.