parameter directive unmarshalling / json formatting not working

14 views
Skip to first unread message

Conor Reedy

unread,
May 26, 2016, 4:02:46 PM5/26/16
to spray.io User List

Hello :)

I have a small problem with the parameters directive.  It seems to be throwing this error 

"too many arguments for method parameters: (pdm: spray.routing.directives.ParamDefMagnet)pdm.Out"

This is happening on version 1.3.2 built against Scala 2.11.7

I've tried to supply this as both .as(CustomMarshaller)  and as .as[ClassName] and both result in this.

When I use something like .as[Int] it does not complain...here is what I have. Nothing special LocalDate is a class in org.joda.time

  implicit val LocalDateUnmarshaller = Unmarshaller[LocalDate](`text/html`, `application/json`, `application/xml`, `application/xhtml+xml`) {
    case HttpEntity.NonEmpty(contentType, data) => {
      new LocalDate(data.asString)
    }
  }

The test I have is as follows:

  "JsonString" should {
    "convert application/json to LocalDate" in {
      val subject = HttpEntity(MediaTypes.`application/json`, "2010-10-10")
      val num     = HttpEntity(MediaTypes.`application/json`, "2")

      subject.as(LocalDateUnmarshaller) should be (Right(new LocalDate("2010-10-10")))
      subject.as[LocalDate]             should be (Right(new LocalDate("2010-10-10")))
    }
  }

Assuming this is correct I should be able to see this working in the parameters directive like:
paramters('date.as[LocalDate]) { (date) => complete ("hey its a ${date.toString}") }

Any suggestions on this?

Thanks,
Conor
Reply all
Reply to author
Forward
0 new messages