我正在使用spray,我需要通过方法返回一个json
对象。使用spray.json获取Json对象
val route =
path("all-modules") {
get {
respondWithMediaType(`text/html`) {
complete(configViewer.findAllModules.toString)
}
}
}
这将打印ConfigResults(S1000,Success,List(testDataTypes, mandate, sdp))
但我需要得到这个作为json
对象。我该怎么做?
我这样
val route =
path("all-modules") {
get {
respondWithMediaType(`application/json`) {
complete{
configViewer.findAllModules
}
}
}
}
尝试它给出了一个编译错误could not find implicit value for parameter marshaller: spray.httpx.marshalling.ToResponseMarshaller
Btw。你通常不需要使用'respondWithMediaType'指令。编组会自动找出使用哪种内容类型。 – jrudolph