blob: e854e9ab6e60bd3df7b11ae01125d59829eb84b7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package scala.scalajs.tools.json
trait JSONDeserializer[T] {
def deserialize(x: JSON): T
}
object JSONDeserializer {
implicit object stringJSON extends JSONDeserializer[String] {
def deserialize(x: JSON): String = Impl.toString(x)
}
implicit object intJSON extends JSONDeserializer[Int] {
def deserialize(x: JSON): Int = Impl.toNumber(x).intValue()
}
implicit object booleanJSON extends JSONDeserializer[Boolean] {
def deserialize(x: JSON): Boolean = Impl.toBoolean(x)
}
implicit def listJSON[T : JSONDeserializer] = new JSONDeserializer[List[T]] {
def deserialize(x: JSON): List[T] = Impl.toList(x).map(fromJSON[T] _)
}
implicit def mapJSON[V : JSONDeserializer] = new JSONDeserializer[Map[String, V]] {
def deserialize(x: JSON): Map[String, V] =
Impl.toMap(x).mapValues(fromJSON[V] _)
}
}
|