diff options
author | Stewart Stewart <stewinsalot@gmail.com> | 2017-03-15 16:10:55 -0700 |
---|---|---|
committer | Stewart Stewart <stewinsalot@gmail.com> | 2017-03-15 16:11:03 -0700 |
commit | 26613a6690823300515156d75bfb51e430b7ae5c (patch) | |
tree | cd893a5e1a5de1447e78ef09f409bc26362e44e6 | |
parent | 6ae573387e623912a164d3e35e2c79065434d978 (diff) | |
download | driver-core-26613a6690823300515156d75bfb51e430b7ae5c.tar.gz driver-core-26613a6690823300515156d75bfb51e430b7ae5c.tar.bz2 driver-core-26613a6690823300515156d75bfb51e430b7ae5c.zip |
reintroduce month format
-rw-r--r-- | src/main/scala/xyz/driver/core/json.scala | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/main/scala/xyz/driver/core/json.scala b/src/main/scala/xyz/driver/core/json.scala index 01efd57..4c5d078 100644 --- a/src/main/scala/xyz/driver/core/json.scala +++ b/src/main/scala/xyz/driver/core/json.scala @@ -7,7 +7,7 @@ import akka.http.scaladsl.unmarshalling.Unmarshaller import spray.json.{DeserializationException, JsNumber, _} import xyz.driver.core.auth.AuthCredentials import xyz.driver.core.time.Time -import xyz.driver.core.date.Date +import xyz.driver.core.date.{Date, Month} import xyz.driver.core.domain.{Email, PhoneNumber} import scala.reflect.runtime.universe._ @@ -81,6 +81,14 @@ object json { } } + implicit val monthFormat = new RootJsonFormat[Month] { + def write(month: Month) = JsNumber(month) + def read(value: JsValue): Month = value match { + case JsNumber(month) if 0 <= month && month <= 11 => date.tagMonth(month.toInt) + case _ => throw DeserializationException("Expected a number from 0 to 11") + } + } + def RevisionInPath[T]: PathMatcher1[Revision[T]] = PathMatcher("""[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}""".r) flatMap { string => Some(Revision[T](string)) |