diff options
author | vlad <vlad@driver.xyz> | 2017-10-02 01:05:42 -0700 |
---|---|---|
committer | vlad <vlad@driver.xyz> | 2017-10-02 01:05:42 -0700 |
commit | d0482b45b6f9149f050c5e5a6dbab6f059229282 (patch) | |
tree | c82ce57536dc2ec51b34f1b6f8159835d95c2cc6 /src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala | |
parent | c5b7f009479930b82f0fb839971eeb2c457dcef0 (diff) | |
download | rest-query-d0482b45b6f9149f050c5e5a6dbab6f059229282.tar.gz rest-query-d0482b45b6f9149f050c5e5a6dbab6f059229282.tar.bz2 rest-query-d0482b45b6f9149f050c5e5a6dbab6f059229282.zip |
DocumentType and ProviderType as enumsv0.5.3
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala index 6b69873..8eef44a 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala @@ -36,7 +36,24 @@ object record { } } - implicit val providerTypeFormat = jsonFormat2(ProviderType.apply) + implicit val providerTypeFormat: RootJsonFormat[ProviderType] = new RootJsonFormat[ProviderType] { + override def read(json: JsValue): ProviderType = 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")) + + ProviderType + .fromString(name) + .getOrElse(deserializationError(s"Unknown provider type: $name")) + + case _ => deserializationError(s"Expected Json Object as Intervention type, but got $json") + } + + override def write(obj: ProviderType) = + JsObject("id" -> obj.id.toJson, "name" -> obj.name.toJson) + } implicit val caseIdFormat = new RootJsonFormat[CaseId] { override def write(caseId: CaseId): JsString = JsString(caseId.toString) |