Created
October 23, 2014 20:19
-
-
Save andyczerwonka/debe3a55c7d7aa3224dc to your computer and use it in GitHub Desktop.
I'm trying to create a JSON serializer in Play 2.3.4 and line #7 give a compiler error saying "No Json deserializer found for type Array[models.Sensor]. Try to implement an implicit Reads or Format for this type." Given there is a default serializer for Array, I assume this should work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class CreateParams(name: String, interval: Int, camera: Boolean, sensors: IndexedSeq[Sensor]) | |
implicit val createParamsReads = new Reads[CreateParams] { | |
def reads(js: JsValue): JsResult[CreateParams] = { | |
val name = (js \ "name").as[String] | |
val interval = (js \ "interval").as[Int] | |
val camera = (js \ "camera").as[Boolean] | |
val sensors = (js \ "sensors").as[IndexedSeq[Sensor]] | |
JsSuccess(CreateParams(name, interval, camera, sensors)) | |
} | |
} | |
implicit val sensorReads = new Reads[Sensor] { | |
def reads(js: JsValue): JsResult[Sensor] = { | |
val name = (js \ "name").as[String] | |
val unit = (js \ "unit").asOpt[String] | |
val scale = (js \ "scale").as[Double] | |
val offset = (js \ "offset").as[Double] | |
val internal = (js \ "internal").as[Boolean] | |
JsSuccess(Sensor(name, unit, scale, offset, internal)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ooops.... wrong order.