diff options
author | vlad <vlad@drivergrp.com> | 2016-11-18 15:09:12 -0800 |
---|---|---|
committer | vlad <vlad@drivergrp.com> | 2016-11-18 15:09:12 -0800 |
commit | eea7df07092cebf7f0c4999d7cf926d56e3c6f19 (patch) | |
tree | 65cf944355b920517b8189f6c893b1d8c748c7cc | |
parent | f307ba3680a094a093f4e3abff22361111de780e (diff) | |
download | driver-core-eea7df07092cebf7f0c4999d7cf926d56e3c6f19.tar.gz driver-core-eea7df07092cebf7f0c4999d7cf926d56e3c6f19.tar.bz2 driver-core-eea7df07092cebf7f0c4999d7cf926d56e3c6f19.zip |
Made EnumJsonFormat a RootJsonFormatv0.9.17
-rw-r--r-- | src/main/scala/xyz/driver/core/json.scala | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/main/scala/xyz/driver/core/json.scala b/src/main/scala/xyz/driver/core/json.scala index 99f7152..3917eca 100644 --- a/src/main/scala/xyz/driver/core/json.scala +++ b/src/main/scala/xyz/driver/core/json.scala @@ -23,7 +23,7 @@ object json { def read(value: JsValue) = value match { case JsNumber(id) => Id[T](id.toLong) - case _ => throw new DeserializationException("Id expects number") + case _ => throw DeserializationException("Id expects number") } } @@ -36,7 +36,7 @@ object json { def read(value: JsValue): Name[T] = value match { case JsString(name) => Name[T](name) - case _ => throw new DeserializationException("Name expects string") + case _ => throw DeserializationException("Name expects string") } } @@ -57,8 +57,8 @@ object json { case JsNumber(millis) => Some(Time(millis.toLong)) case _ => None } - .getOrElse(throw new DeserializationException("Time expects number")) - case _ => throw new DeserializationException("Time expects number") + .getOrElse(throw DeserializationException("Time expects number")) + case _ => throw DeserializationException("Time expects number") } } @@ -75,11 +75,11 @@ object json { def read(value: JsValue): Revision[T] = value match { case JsString(revision) => Revision[T](revision) - case _ => throw new DeserializationException("Revision expects uuid string") + case _ => throw DeserializationException("Revision expects uuid string") } } - class EnumJsonFormat[T](mapping: (String, T)*) extends JsonFormat[T] { + class EnumJsonFormat[T](mapping: (String, T)*) extends RootJsonFormat[T] { private val map = mapping.toMap override def write(value: T): JsValue = { @@ -91,7 +91,7 @@ object json { override def read(json: JsValue): T = json match { case JsString(name) => - map.getOrElse(name, throw new DeserializationException(s"Value $name is not found in the mapping $map")) + map.getOrElse(name, throw DeserializationException(s"Value $name is not found in the mapping $map")) case _ => deserializationError("Expected string as enumeration value, but got " + json) } } |