0

New to Scala to go easy on me!

I'm using spray atm and posting requests in. I'm looking to convert the post data to a case class but it throws an error could not find implicit value for parameter um: spray.httpx.unmarshalling.FromRequestUnmarshaller. What might I be doing incorrect? The Documentation is a bit confusing.

post {
    entity(as[TextMessage]) { txt =>
        println(txt.body)
        complete("")
    }
}

And my Case Class case class TextMessage( body: String, from: String)

From the docs this should work off the bat.

Ideas?

Edit: The data isn't being posted as JSON it's posted as form data i.e. application/x-www-form-urlencoded

user3750194
  • 387
  • 2
  • 11

2 Answers2

0

Make sure that the JsonFormat for the TextMessage type is in the scope, so that Spray cand find out how to marshall that type.

Check this link

Community
  • 1
  • 1
Jorge
  • 1,136
  • 9
  • 15
0

I haven't parsed form data with spray so I don't know if easier way exists but I would use formFields directive.

val textMessageEntity = formFields('body, 'from).as(TextMessage)

post {
    textMessageEntity { txt =>
        println(txt.body)
        complete("")
    }
}

Here is more information about formFields directive: http://spray.io/documentation/1.2.2/spray-routing/form-field-directives/formFields/

Mustafa Simav
  • 1,019
  • 5
  • 6