diff options
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, 19 insertions, 0 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 e378dbd..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,6 +36,25 @@ object record { } } + 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) override def read(json: JsValue): CaseId = json match { |