-2

i am new to akka http and i am having difficulty in marshalling and un-marshalling of my case class here is my code

case class Event(uuid:String)

//main class 
class demo {

    val route: Route =

    post {
            path("create-event") {
              entity(as[Event]) { event =>
                  complete("event created")
                }
              }
            }
          }
    }

i am getting a compile time error on this line

entity(as[Event]) { event =>

 could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[models.event.Event]            
swaheed
  • 3,671
  • 10
  • 42
  • 103

2 Answers2

2

There is an easy way to solve this. akka-http-jackson has an implementation for Request Unmarshaller.

sbt add lib:

"de.heikoseeberger"                         %% "akka-http-jackson"             % "1.27.0"

and then in your code

import de.heikoseeberger.akkahttpjackson.JacksonSupport._
YouXiang-Wang
  • 1,119
  • 6
  • 15
0

By default, Akka-Http uses spray to marshal and unmarshal json and the error is because no implicit converter which is used for conversion is defined.

import spray.json.DefaultJsonProtocol
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import spray.json._

trait EventProtocol extends DefaultJsonProtocol {
  implicit val eventJsonFormat = jsonFormat1(Event)
}

class demo extends SprayJsonSupport with EventProtocol {
// your code
}

The detailed steps are provided in akka-http documentation

Hope it helps!!

Anand Sai
  • 1,566
  • 7
  • 11