could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.Unmarshaller

1,593 views
Skip to first unread message

hervé DARRITCHON

unread,
Aug 17, 2016, 9:37:38 AM8/17/16
to Akka User List
Hi !!

One more subject about this topic :(
I looked deeply in this group, found some post and solutions (materializer, add SprayJsonSupport, read Konrad's post, ...) but nothing work !

Moreover, I have several class that parsed some Json et 2 of them works et with the last I have this pb :(

This Actor class is used to translate a JwtToken into an object.

Interpreter.scala
import java.sql.Timestamp

import akka.actor.{Actor, ActorLogging, Props}
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.{ActorMaterializer, ActorMaterializerSettings}
import com.orange.spectre.model.{JwtToken, JwtTokenHeader, JwtTokenPayload, RawJwtToken}
import spray.json.DefaultJsonProtocol

import scala.concurrent.Future

trait TokenPartsJsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
implicit val jwtTokenHeaderFormat = jsonFormat2(JwtTokenHeader)
implicit val jwtTokenPayloadFormat = jsonFormat5(JwtTokenPayload)
}

case class StartInterpreterMessage()

case class StopInterpreterMessage()

object Interpreter {

def props(token: RawJwtToken): Props = Props(new Interpreter(token))
}

/**
* Created by Hervé Darritchon on 17/08/2016.
*
*/
class Interpreter(rawToken: RawJwtToken) extends Actor with ActorLogging with TokenPartsJsonSupport {

// Dispatcher is used as implicit for all the future call methods in this class
import context.dispatcher

final implicit val materializer: ActorMaterializer = ActorMaterializer(ActorMaterializerSettings(context.system))


def translate(rawToken: RawJwtToken): Option[JwtToken] = {
val parts: Array[String] = rawToken.accessToken.split(".")

val decodedHeader: String = java.util.Base64.getDecoder.decode(parts(0)).toString
val decodedPayload: String = java.util.Base64.getDecoder.decode(parts(1)).toString

val payload: Future[Either[String, JwtTokenPayload]] = Unmarshal(decodedPayload).to[JwtTokenPayload].map(Right(_))

}

private val token: Option[JwtToken] = translate(rawToken)


JwtTokenPayload.scala
  * Created by Hervé Darritchon on 30/05/2016.
*
*/
case class JwtTokenPayload(iat: Long, iss: String, sub: String, exp: Long, user_id: String)

When I compile my program, I get a compile error :
[error] .../actors/Interpreter.scala:54: could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.Unmarshaller[String,model.JwtTokenPayload]
[error]     val payload: Future[Either[String, JwtTokenPayload]] = Unmarshal(decodedPayload).to[JwtTokenPayload].map(Right(_))
[error]                                                                                        ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 0 s, completed 17 août 2016 15:14:56

I don't understand why, sorry :(

I have my implicit Format, I have my ec, my materializer. It should work but it doesn't. I have missed something I gues but can't find what :)

Thanks !

hervé DARRITCHON

unread,
Aug 17, 2016, 10:26:38 AM8/17/16
to Akka User List

Some more information.

In IntelliJ, if I do a Cmd+Sht+P on the Unmarshal method, 


I get for the unmarshal()



I get for the unmarshal().to[]



I hope it helps :)

Thx

Владимир Морозов

unread,
Aug 18, 2016, 4:04:23 AM8/18/16
to Akka User List
Hi,

please change your code for parse payload to

```
import spray.json._
val payload: Either[String, JwtTokenPayload] = Right(decodedPayload.parseJson.convertTo[JwtTokenPayload])
```

It must work

среда, 17 августа 2016 г., 17:26:38 UTC+3 пользователь hervé DARRITCHON написал:
Reply all
Reply to author
Forward
0 new messages