みなさん、こんにちは :) Scala と Play!Framework (バージョン 2.1) を始めて約 16 時間です。Jerksonを使用する Anorm を使用して、この Play!2.0 チュートリアルに従っています。私が理解していることから、2.1 では、適切な JSON フォーマッターがあれば、すぐに使用できます。
JSON サービスは次のとおりです。
def listBars() = Action {
val bars = Bar.findAll()
Ok(Json.toJson(bars)).as("application/json")
}
Bar.scala は次のとおりです。
case class Bar(id: Pk[Long], name: String)
object Bar {
implicit var anormLongPkFormat = new Format[Pk[Long]] {
def writes(key: Pk[Long]): JsValue = Json.toJson(key.toString)
def reads(jv: JsValue): JsResult[Pk[Long]] = JsSuccess( -?- )
}
implicit val barFormat = Json.format[Bar]
def findAll(): Seq[Bar] = {...}
}
を使用しJson.format[Bar]
ていますが、 には別のフォーマッタが必要であることがわかりますanorm.Pk[Long]
。メソッドは必要ありませんreads
。今のところ、値を提供したいだけです。ただし、コンパイラにはreads
メソッドが必要です。私はそれをコンパイルする方法に完全に途方に暮れていますreads
.
よろしくお願いします