diff options
author | Aleksandr <ognelisar@gmail.com> | 2017-10-12 10:44:54 +0700 |
---|---|---|
committer | Aleksandr <ognelisar@gmail.com> | 2017-10-12 10:44:54 +0700 |
commit | f525ab2604cc5d1366c852bdbcb4d912bbcea800 (patch) | |
tree | 4fe4b35e1f474e2dc85a8885dc4c9002f3ea46c2 /src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/slotarm.scala | |
parent | 9198729ebf3d20b650b4467daa0d484a3148f01c (diff) | |
parent | e15415d69ec990d5243e58704e232e619b80aa6f (diff) | |
download | rest-query-f525ab2604cc5d1366c852bdbcb4d912bbcea800.tar.gz rest-query-f525ab2604cc5d1366c852bdbcb4d912bbcea800.tar.bz2 rest-query-f525ab2604cc5d1366c852bdbcb4d912bbcea800.zip |
All merge conflicts are resolved
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/slotarm.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/slotarm.scala | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/slotarm.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/slotarm.scala new file mode 100644 index 0000000..192bd6a --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/slotarm.scala @@ -0,0 +1,44 @@ +package xyz.driver.pdsuidomain.formats.json.sprayformats + +import spray.json._ +import xyz.driver.pdsuicommon.domain.{LongId, StringId} +import xyz.driver.pdsuidomain.entities.{SlotArm, Trial} + +object slotarm { + import DefaultJsonProtocol._ + import common._ + + def applyUpdateToArm(json: JsValue, orig: SlotArm): SlotArm = json match { + case JsObject(fields) => + val name = fields + .get("name") + .map(_.convertTo[String]) + .getOrElse(deserializationError(s"Arm json object does not contain `name` field: $json")) + orig.copy(name = name) + + case _ => deserializationError(s"Expected Json Object as partial Arm, but got $json") + } + + def slotArmFormat: RootJsonFormat[SlotArm] = new RootJsonFormat[SlotArm] { + override def write(obj: SlotArm): JsValue = + JsObject( + "id" -> obj.id.toJson, + "name" -> obj.name.toJson, + "originalName" -> obj.originalName.toJson, + "trialId" -> obj.trialId.toJson + ) + + override def read(json: JsValue): SlotArm = json.asJsObject.getFields("trialId", "name") match { + case Seq(trialId, name) => + SlotArm( + id = LongId(0), + name = name.convertTo[String], + trialId = trialId.convertTo[StringId[Trial]], + originalName = name.convertTo[String] + ) + + case _ => deserializationError(s"Expected Json Object as Arm, but got $json") + } + } + +} |