2015-06-07 107 views
2

我可以在播放框架中使用spray-json進行json序列化嗎? 我已經嘗試過,但它似乎不工作。使用噴泉json播放框架

我想一個簡單的動作

def getColor(sn: Int) = Action { 
      import MyJsonProtocol._ 
      val c = Color("color",33,23,99) 
      Ok(c.toJson) 
      } 

我收到以下錯誤

play.sbt.PlayExceptions$CompilationException: Compilation error[Cannot write an instance of spray.json.JsValue to HTTP response. Try to define a Writeable[spray.json.JsValue]] 

回答

1

滑稽;)我固定它自己通過調用的toJSON

Ok(c.toJson.prettyPrint) 
的prettyPrint方法