我正在使用喷雾剂,我需要退回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
您需要告诉 Spray 它应该如何序列化您的案例类。
只需配置类似的东西
object JsonSupport {
implicit val formatConfigResults = jsonFormat3(ConfigResults)
}
jsonFormat'number' 中的数字代表案例类中的成员数量。
然后,您只需将定义此隐式的类导入到您的路由中。
import JsonSupport._
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)