我正在使用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