aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/core/json.scala
diff options
context:
space:
mode:
authorStewart Stewart <stewart@driver.xyz>2017-05-17 23:13:07 -0400
committerStewart Stewart <stewart@driver.xyz>2017-05-17 23:13:07 -0400
commitcc5144977ee247e0de5a119b4c86b3a16e1dd6e6 (patch)
treea0b662716844da54ecafa3193e59fbaaeaad5fed /src/main/scala/xyz/driver/core/json.scala
parent97e75b8d777c6661461493b28d91559fabf237ba (diff)
downloaddriver-core-cc5144977ee247e0de5a119b4c86b3a16e1dd6e6.tar.gz
driver-core-cc5144977ee247e0de5a119b4c86b3a16e1dd6e6.tar.bz2
driver-core-cc5144977ee247e0de5a119b4c86b3a16e1dd6e6.zip
make idFormat work with UUID
Diffstat (limited to 'src/main/scala/xyz/driver/core/json.scala')
-rw-r--r--src/main/scala/xyz/driver/core/json.scala15
1 files changed, 3 insertions, 12 deletions
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)))