diff options
author | Aleksandr <ognelisar@gmail.com> | 2018-04-10 11:12:33 +0700 |
---|---|---|
committer | Aleksandr <ognelisar@gmail.com> | 2018-04-10 11:12:33 +0700 |
commit | d396c3b6b510c3ed77c17c64df3e58af4146b9a4 (patch) | |
tree | 3533ce548006a836e947e77aa9890d2da666c2fa /src/main/scala/xyz/driver/core/json.scala | |
parent | 9a73fb5628f494bcae73496012f8c3baf13a26f1 (diff) | |
parent | 1f49149ba768ac86263d11cb18e7a365b0bb0210 (diff) | |
download | driver-core-d396c3b6b510c3ed77c17c64df3e58af4146b9a4.tar.gz driver-core-d396c3b6b510c3ed77c17c64df3e58af4146b9a4.tar.bz2 driver-core-d396c3b6b510c3ed77c17c64df3e58af4146b9a4.zip |
Merge branch 'master' into TM-1431
Diffstat (limited to 'src/main/scala/xyz/driver/core/json.scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/json.scala | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/main/scala/xyz/driver/core/json.scala b/src/main/scala/xyz/driver/core/json.scala index 06a8837..e7efce6 100644 --- a/src/main/scala/xyz/driver/core/json.scala +++ b/src/main/scala/xyz/driver/core/json.scala @@ -34,16 +34,24 @@ object json { } } - implicit def idFormat[T] = new RootJsonFormat[Id[T]] { + implicit def idFormat[T]: JsonFormat[Id[T]] = new JsonFormat[Id[T]] { def write(id: Id[T]) = JsString(id.value) - def read(value: JsValue) = value match { + def read(value: JsValue): Id[T] = value match { case JsString(id) if Try(UUID.fromString(id)).isSuccess => Id[T](id.toLowerCase) case JsString(id) => Id[T](id) case _ => throw DeserializationException("Id expects string") } } + implicit def taggedFormat[F, T](implicit underlying: JsonFormat[F]): JsonFormat[F @@ T] = new JsonFormat[F @@ T] { + import tagging._ + + override def write(obj: F @@ T): JsValue = underlying.write(obj) + + override def read(json: JsValue): F @@ T = underlying.read(json).tagged[T] + } + 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))) |