diff options
Diffstat (limited to 'vfd-backend')
-rw-r--r-- | vfd-backend/app/controllers/Application.scala | 19 | ||||
-rw-r--r-- | vfd-backend/app/util/package.scala | 22 |
2 files changed, 25 insertions, 16 deletions
diff --git a/vfd-backend/app/controllers/Application.scala b/vfd-backend/app/controllers/Application.scala index f048a07..6bd066d 100644 --- a/vfd-backend/app/controllers/Application.scala +++ b/vfd-backend/app/controllers/Application.scala @@ -1,5 +1,6 @@ package controllers +import util._ import play.api._ import play.api.mvc._ import play.api.Play.current @@ -21,22 +22,8 @@ object Application extends Controller { Ok(views.html.index()) } - implicit object DataFrameFormat extends Format[DataFrame] { - import org.scalajs.spickling._ - import org.scalajs.spickling.playjson._ - import play.api.data.validation.ValidationError - - PicklerRegistry.register[DataFrame] - - def writes(o: DataFrame): JsValue = PicklerRegistry.pickle(o) - - def reads(j: JsValue): JsResult[DataFrame] = PicklerRegistry.unpickle(j) match { - case df: DataFrame => JsSuccess(df) - case _ => JsError("unpickling yielded wrong type") - } - } - - //implicit val dataFrameFormat = Json.format[DataFrame] + + implicit val dataFrameFormat = spicklerFormat[DataFrame] implicit val dataFrameFormatter = FrameFormatter.jsonFrame[DataFrame] def socket = WebSocket.acceptWithActor[String, DataFrame] { request => diff --git a/vfd-backend/app/util/package.scala b/vfd-backend/app/util/package.scala new file mode 100644 index 0000000..4a6d2e6 --- /dev/null +++ b/vfd-backend/app/util/package.scala @@ -0,0 +1,22 @@ + + +import org.scalajs.spickling._ +import org.scalajs.spickling.playjson._ +import play.api.data.validation.ValidationError +import play.api.libs.json._ + + +package object util { + + def spicklerFormat[A](implicit manifest: Manifest[A], pickler: Pickler[A], unpickler: Unpickler[A]) = new Format[A] { + PicklerRegistry.register[A] + + def writes(o: A): JsValue = PicklerRegistry.pickle(o) + + def reads(j: JsValue): JsResult[A] = PicklerRegistry.unpickle(j) match { + case a: A => JsSuccess(a) + case _ => JsError("unpickling yielded wrong type") + } + } + +}
\ No newline at end of file |