Implicit value issue for FromRequestUnmarshaller in akka-http with spray-json

1,784 views
Skip to first unread message

Arthur Kushka

unread,
Mar 15, 2015, 7:16:37 PM3/15/15
to akka...@googlegroups.com
Hi. I was faced with a typical error with spray-json and akka-http that easy to find in Google, but none of solutions helps me.

Scala fail compiling in place where I parsing request body with `entity` directive. As error say, they can`t find implicit value for unmarshaller, but formatter and `SprayJsonSupport` are present in context (in documentation written that that`s enough).

Below is compiler message and my code.
Please help me with finding solution of this problem.

[error] /home/arhelmus/techmedia/akka-http/src/main/scala/utils/CustomDirectives.scala:31: could not find implicit value for parameter um: akka.http.unmarshalling.FromRequestUnmarshaller[utils.Credentials]
[error]     entity(as[Credentials]).flatMap { credentials =>


package utils

import akka.http.marshallers.sprayjson.SprayJsonSupport
import akka.http.server.Directive1
import models.User
import spray.json._

case class Credentials(login: String, password: String)

trait
Protocols extends DefaultJsonProtocol {
 
implicit val formatter: RootJsonFormat[Credentials] = jsonFormat2(Credentials.apply)
}

object CustomDirectives extends CustomDirectives

trait
CustomDirectives extends SprayJsonSupport with Protocols {

 
import akka.http.server.directives.BasicDirectives._
 
import akka.http.server.directives.MarshallingDirectives._
 
import akka.http.server.directives.ParameterDirectives._

 
def authenticateByToken: Directive1[User] =
    parameter
("token").flatMap { code =>
      provide
(User(code, "asdsada", "asdsadasd"))
   
}

 
def authenticateByCredentials: Directive1[User] = {
    entity
(as[Credentials]).flatMap { credentials =>
      provide
(User(credentials.login, credentials.login, credentials.password))
   
}
 
}

}

James Mulcahy

unread,
Mar 15, 2015, 7:29:23 PM3/15/15
to akka...@googlegroups.com
I think you need an in-scope implicit FlowMaterializer (or perhaps an ActorFlowMaterializer, if you're on M3.  I think that may have been resolved in M4 though)

James

Sent from my iPhone
--
>>>>>>>>>> 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+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Paul Cleary

unread,
Mar 21, 2015, 6:00:40 PM3/21/15
to akka...@googlegroups.com
Ugh, I hit this same issue using 1.0-M4; you still need an implicit `ActorFlowMaterializer` :(

Kabir Idris

unread,
Jul 23, 2015, 9:27:07 AM7/23/15
to Akka User List, arhe...@gmail.com
Hi all, Im facing the same error in akka-http 1.0

Heiko Seeberger

unread,
Jul 23, 2015, 1:54:53 PM7/23/15
to akka...@googlegroups.com
Do you have an implicit Materializer in scope?

Heiko

--

Heiko Seeberger
Twitter: @hseeberger

Kabir Idris

unread,
Jul 23, 2015, 4:04:24 PM7/23/15
to akka...@googlegroups.com

Yes I do have an implicit actor materializer  in scope


You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/Vhm_zkTajJk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Heiko Seeberger

unread,
Jul 24, 2015, 12:59:44 AM7/24/15
to akka...@googlegroups.com
Can you put the code up on GitHub or such? Else it’s pure speculation. 

Wrt speculation: Depending on what you are doing you might also need an implicit ExecutionContext.

Heiko

--

Heiko Seeberger
Twitter: @hseeberger

On 23 Jul 2015, at 22:04, Kabir Idris <bink...@gmail.com> wrote:

Yes I do have an implicit actor materializer  in scope 


On Thu, 23 Jul 2015 6:54 pm Heiko Seeberger <loe...@posteo.de> wrote:
Do you have an implicit Materializer in scope?

Heiko

--

Heiko Seeberger
Twitter: @hseeberger

On 23 Jul 2015, at 15:25, Kabir Idris <bink...@gmail.com> wrote:

Hi all, Im facing the same error in akka-http 1.0 



On Monday, March 16, 2015 at 12:16:37 AM UTC+1, Arthur Kushka wrote:
Hi. I was faced with a typical error with spray-json and akka-http that easy to find in Google, but none of solutions helps me.

Scala fail compiling in place where I parsing request body with `entity` directive. As error say, they can`t find implicit value for unmarshaller, but formatter and `SprayJsonSupport` are present in context (in documentation written that that`s enough).

Below is compiler message and my code.
Please help me with finding solution of this problem.

[error] /home/arhelmus/techmedia/akka-http/src/main/scala/utils/CustomDirectives.scala:31: could notfind implicit value for parameter um:akka.http.unmarshalling.FromRequestUnmarshaller[utils.Credentials]
signature.asc

Johannes Rudolph

unread,
Jul 24, 2015, 4:04:41 AM7/24/15
to Akka User List, arhe...@gmail.com, bink...@gmail.com
I agree, this is more confusing than necessary. I created https://github.com/akka/akka/issues/18064 to improve the situation.

Johannes

Kabir Idris

unread,
Jul 24, 2015, 5:19:06 AM7/24/15
to Akka User List, arhe...@gmail.com
Hi Heiko,
Here is my code

 implicit val system = ActorSystem()

   
implicit val executor: ExecutionContext = system.dispatcher
    val log
: LoggingAdapter = Logging(system, getClass)
   
implicit val materializer = ActorMaterializer()


 
Http().bindAndHandle(routes, httpInterface, httpPort)




On Monday, March 16, 2015 at 12:16:37 AM UTC+1, Arthur Kushka wrote:

Harit Himanshu

unread,
Jul 28, 2015, 5:10:08 PM7/28/15
to Akka User List, arhe...@gmail.com, bink...@gmail.com
I have similar issue, how did you people resolve it?

Heiko Seeberger

unread,
Jul 29, 2015, 12:45:19 AM7/29/15
to akka...@googlegroups.com, bink...@gmail.com
You need to show the definition of routes. I assume (speculation again) that it’s a method in a different scope which doesn’t take an implicit Materializer (or EC).

Heiko

--

Heiko Seeberger
Twitter: @hseeberger

charles adetiloye

unread,
Aug 21, 2015, 12:38:58 AM8/21/15
to Akka User List, bink...@gmail.com, loe...@posteo.de
@Heiko... please how did you solve it ?

peter janovsky

unread,
Aug 22, 2015, 1:43:34 AM8/22/15
to Akka User List
Charles, as Heiko pointed out you need to have an implicit Materializer in scope.  This resolved my compilation error
Reply all
Reply to author
Forward
0 new messages