diff options
author | Stewart Stewart <stewinsalot@gmail.com> | 2016-12-01 15:53:45 -0800 |
---|---|---|
committer | Stewart Stewart <stewinsalot@gmail.com> | 2016-12-01 15:53:45 -0800 |
commit | 41e2e7c0e032490ccfae1e48e849b2dce7e18d12 (patch) | |
tree | dc4ae13765cbfecd4af8842eefaa16b51121c390 /src/main/scala/xyz/driver/core/json.scala | |
parent | 03376ce4b563394c544ff2228a9a8146d0893b0c (diff) | |
parent | 116b4a75361d68f1eb035cf748fe5bc3c5f6a3d6 (diff) | |
download | driver-core-41e2e7c0e032490ccfae1e48e849b2dce7e18d12.tar.gz driver-core-41e2e7c0e032490ccfae1e48e849b2dce7e18d12.tar.bz2 driver-core-41e2e7c0e032490ccfae1e48e849b2dce7e18d12.zip |
Merge branch 'master' into decouple-codegen
Diffstat (limited to 'src/main/scala/xyz/driver/core/json.scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/json.scala | 16 |
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) |