diff options
author | Vlad Uspensky <v.uspenskiy@icloud.com> | 2016-11-29 15:45:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-29 15:45:29 -0800 |
commit | 116b4a75361d68f1eb035cf748fe5bc3c5f6a3d6 (patch) | |
tree | 4e446b1c3c32c986ce2350bc3a994da43250e8d0 /src/main/scala/xyz/driver/core/json.scala | |
parent | 66a01327a9b68d4756a9c61229027726e2f3d152 (diff) | |
parent | 2f2eeb273b1cdc89c5283412ea85977665d9f26b (diff) | |
download | driver-core-116b4a75361d68f1eb035cf748fe5bc3c5f6a3d6.tar.gz driver-core-116b4a75361d68f1eb035cf748fe5bc3c5f6a3d6.tar.bz2 driver-core-116b4a75361d68f1eb035cf748fe5bc3c5f6a3d6.zip |
Merge pull request #4 from drivergroup/string-ids
Changed ids underlying type to String and made Ids and Names — value-…
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) |