Reputation: 20242
I have the following case class:
case class Customer(name: String)
That is encoded like this:
class ServiceJsonProtocol extends DefaultJsonProtocol {
implicit val customerProtocol = jsonFormat1(Customer)
}
The problem is that for this code:
val route =
path("customer") {
post {
entity(as[Customer]) {
customer => complete {
customers.add(customer)
s"got customer with name ${customer.name}"
}
}
}
I am getting this:
could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[Customer]
[error] entity(as[Customer]) {
What is the issue?
Upvotes: 1
Views: 369
Reputation: 4133
You have to extend SprayJsonSupport. This compiles:
import spray.json._
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
case class Customer(name: String)
object ServiceJsonProtocol extends DefaultJsonProtocol {
implicit val customerProtocol = jsonFormat1(Customer)
}
class RateRoutes extends SprayJsonSupport {
import ServiceJsonProtocol._
val route =
path("customer") {
post {
entity(as[Customer]) {
customer => complete {
customers.add(customer)
s"got customer with name ${customer.name}"
}
}
}
}
}
I suppose your using akka http. With Spray this error should not happen.
Upvotes: 4