好的......我有这个:
def convertPost = extract {
_.request.entity.asString.parseJson.convertTo[CustomClass]
}
private def myRoute: Route =
(post & terminalPath("routeness")) {
convertPost { req =>
detach() {
ThingHandler.getMyResults( req )
}
}
}
但我想模仿它,就像这样:
def convertPost[T] = extract {
_.request.entity.asString.parseJson.convertTo[T]
}
private def myRoute: Route =
(post & terminalPath("routeness")) {
convertPost[CustomClass] { req =>
detach() {
ThingHandler.getMyResults( req )
}
}
}
但这不起作用。我正在使用spray-json-shapeless。我的错误是
Error:(28, 50) Cannot find JsonReader or JsonFormat type class for T
_.request.entity.asString.parseJson.convertTo[T]
^
当我尝试:
def getStuff[T] = extract {
_.request.entity.asInstanceOf[T] // .convertTo[T]
}
它给出了:
spray.http.HttpEntity$NonEmpty cannot be cast to com.stuff.CustomClass