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 !