From cc5144977ee247e0de5a119b4c86b3a16e1dd6e6 Mon Sep 17 00:00:00 2001 From: Stewart Stewart Date: Wed, 17 May 2017 23:13:07 -0400 Subject: make idFormat work with UUID --- src/main/scala/xyz/driver/core/json.scala | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src/main') diff --git a/src/main/scala/xyz/driver/core/json.scala b/src/main/scala/xyz/driver/core/json.scala index 6f772f3..b9d0745 100644 --- a/src/main/scala/xyz/driver/core/json.scala +++ b/src/main/scala/xyz/driver/core/json.scala @@ -18,7 +18,7 @@ import xyz.driver.core.time.Time object json { import DefaultJsonProtocol._ - private def UuidInPath[T]: PathMatcher1[Id[T]] = PathMatchers.JavaUUID.map((id: UUID) => Id[T](id.toString)) + private def UuidInPath[T]: PathMatcher1[Id[T]] = PathMatchers.JavaUUID.map((id: UUID) => Id[T](id.toString.toLowerCase)) def IdInPath[T]: PathMatcher1[Id[T]] = UuidInPath[T] | new PathMatcher1[Id[T]] { def apply(path: Path) = path match { @@ -27,25 +27,16 @@ object json { } } - implicit def uuidFormat[T] = new RootJsonFormat[Id[T]] { + implicit def idFormat[T] = new RootJsonFormat[Id[T]] { def write(id: Id[T]) = JsString(id.value) def read(value: JsValue) = value match { case JsString(id) if Try(UUID.fromString(id)).isSuccess => Id[T](id.toLowerCase) - case JsString(id) => throw DeserializationException("Expected Id as Uuid string") + case JsString(id) => Id[T](id) case _ => throw DeserializationException("Id expects string") } } - def idFormat[T] = new RootJsonFormat[Id[T]] { - def write(id: Id[T]) = JsString(id.value) - - def read(value: JsValue) = value match { - case JsString(id) => Id[T](id) - case _ => throw DeserializationException("Id expects string") - } - } - def NameInPath[T]: PathMatcher1[Name[T]] = new PathMatcher1[Name[T]] { def apply(path: Path) = path match { case Path.Segment(segment, tail) => Matched(tail, Tuple1(Name[T](segment))) -- cgit v1.2.3