Okay so.... I have this:
def convertPost = extract {
_.request.entity.asString.parseJson.convertTo[CustomClass]
}
private def myRoute: Route =
(post & terminalPath("routeness")) {
convertPost { req =>
detach() {
ThingHandler.getMyResults( req )
}
}
}
but I want to template it, like this:
def convertPost[T] = extract {
_.request.entity.asString.parseJson.convertTo[T]
}
private def myRoute: Route =
(post & terminalPath("routeness")) {
convertPost[CustomClass] { req =>
detach() {
ThingHandler.getMyResults( req )
}
}
}
But that doesn't work. I am using spray-json-shapeless. My error is
Error:(28, 50) Cannot find JsonReader or JsonFormat type class for T
_.request.entity.asString.parseJson.convertTo[T]
^
when I try:
def getStuff[T] = extract {
_.request.entity.asInstanceOf[T] // .convertTo[T]
}
it gives:
spray.http.HttpEntity$NonEmpty cannot be cast to com.stuff.CustomClass