aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/core/json.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/xyz/driver/core/json.scala')
-rw-r--r--src/main/scala/xyz/driver/core/json.scala16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/main/scala/xyz/driver/core/json.scala b/src/main/scala/xyz/driver/core/json.scala
index 3917eca..cc27944 100644
--- a/src/main/scala/xyz/driver/core/json.scala
+++ b/src/main/scala/xyz/driver/core/json.scala
@@ -12,18 +12,16 @@ import scala.reflect.runtime.universe._
object json {
- def IdInPath[T]: PathMatcher1[Id[T]] =
- PathMatcher("""[+-]?\d*""".r) flatMap { string =>
- try Some(Id[T](string.toLong))
- catch { case _: IllegalArgumentException => None }
- }
+ def IdInPath[T]: PathMatcher1[Id[T]] = new PathMatcher1[Id[T]] {
+ def apply(path: Path) = Matched(Path.Empty, Tuple1(Id[T](path.toString)))
+ }
implicit def idFormat[T] = new RootJsonFormat[Id[T]] {
- def write(id: Id[T]) = JsNumber(id)
+ def write(id: Id[T]) = JsString(id.value)
def read(value: JsValue) = value match {
- case JsNumber(id) => Id[T](id.toLong)
- case _ => throw DeserializationException("Id expects number")
+ case JsString(id) => Id[T](id)
+ case _ => throw DeserializationException("Id expects string")
}
}
@@ -32,7 +30,7 @@ object json {
}
implicit def nameFormat[T] = new RootJsonFormat[Name[T]] {
- def write(name: Name[T]) = JsString(name)
+ def write(name: Name[T]) = JsString(name.value)
def read(value: JsValue): Name[T] = value match {
case JsString(name) => Name[T](name)