diff options
author | Aleksandr <ognelisar@gmail.com> | 2018-04-10 10:27:12 +0700 |
---|---|---|
committer | Aleksandr <ognelisar@gmail.com> | 2018-04-10 10:27:12 +0700 |
commit | cd4d77b563c7da5600111f7220dd69c732dc495c (patch) | |
tree | c89d6032616f2be3aa278f24492f8908afa8a43c /src/main/scala/xyz/driver/core/json.scala | |
parent | fc7355c69eeab8334ea066a434476d227e9dc399 (diff) | |
parent | 57ee8fa785c3815e45e473e5625d6e3cb1cd9402 (diff) | |
download | driver-core-cd4d77b563c7da5600111f7220dd69c732dc495c.tar.gz driver-core-cd4d77b563c7da5600111f7220dd69c732dc495c.tar.bz2 driver-core-cd4d77b563c7da5600111f7220dd69c732dc495c.zip |
Merge branch 'master' into FIX-TIME-COMPARISSON
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))) |