Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spray-json error: could not find implicit value for parameter um

I have this case class

case class Person(val name: String)

object JsonImplicits extends DefaultJsonProtocol {
  implicit val impPerson = jsonFormat1(Person)
}

I'm trying spray-json in order to parse post request:

  post {
    entity(as[Person]) { person =>
      complete(person)
    }
  }

However I get when I try to compile this:

src/main/scala/com/example/ServiceActor.scala:61: error: could not find implicit value for parameter um: spray.httpx.unmarshalling.FromRequestUnmarshaller[com.example.Person]

I don't understand what's happening, how can I fix this to be working?

thanks

like image 741
Jas Avatar asked Jan 05 '14 09:01

Jas


1 Answers

Spray's 'entity[E]' directive requires implicit marshaller in its scope for the type E. JsonImplicits object creates json marshaller and unmarshaller for the type E.

You need to make sure that implicit val impPerson is in the scope, in other words put import JsonImplicits._ above the route definition.

like image 88
vitalii Avatar answered Oct 18 '22 01:10

vitalii