diff options
author | Marvin Bertin <marvin.bertin@gmail.com> | 2017-10-03 13:09:49 -0700 |
---|---|---|
committer | Marvin Bertin <marvin.bertin@gmail.com> | 2017-10-03 13:09:49 -0700 |
commit | 98d6f3d136a16310300e23b12e6b730ac7ade6b6 (patch) | |
tree | 34ef97bc59f3c34d20a18cd65107655d319097fc /src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala | |
parent | 1d0202a3964637ffb93180a1c89617633ab5ab18 (diff) | |
parent | 0653b90dddc294fddb0e81059aef00b202113d78 (diff) | |
download | rest-query-98d6f3d136a16310300e23b12e6b730ac7ade6b6.tar.gz rest-query-98d6f3d136a16310300e23b12e6b730ac7ade6b6.tar.bz2 rest-query-98d6f3d136a16310300e23b12e6b730ac7ade6b6.zip |
Merge branch 'add-slot-eligibility-arms' into trial-46-disease-entity
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala index baf1b4e..e3f6a9c 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/document.scala @@ -28,6 +28,25 @@ object document { implicit val documentMetaFormat: RootJsonFormat[Meta] = jsonFormat3(Meta.apply) + implicit val documentTypeFormat: RootJsonFormat[DocumentType] = new RootJsonFormat[DocumentType] { + override def read(json: JsValue): DocumentType = json match { + case JsObject(fields) => + val name = fields + .get("name") + .map(_.convertTo[String]) + .getOrElse(deserializationError(s"Intervention type json object does not contain `name` field: $json")) + + DocumentType + .fromString(name) + .getOrElse(deserializationError(s"Unknown document type: $name")) + + case _ => deserializationError(s"Expected Json Object as Intervention type, but got $json") + } + + override def write(obj: DocumentType) = + JsObject("id" -> obj.id.toJson, "name" -> obj.name.toJson) + } + implicit val fullDocumentMetaFormat = new RootJsonFormat[TextJson[Meta]] { override def write(obj: TextJson[Meta]): JsValue = obj.content.toJson override def read(json: JsValue) = TextJson(documentMetaFormat.read(json)) |