aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/record.scala
diff options
context:
space:
mode:
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.scala19
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)