-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSON.scala
58 lines (43 loc) · 1.19 KB
/
JSON.scala
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Created by yuvals on 27/06/2017.
*/
import JsonDouble._
import JsonInt._
object JSON {
def serialize[T](obj: T)(implicit conv: T => JsonObject): JsonObject = {
obj
}
case class Address(street: String, number: Int, city: String)
case class Person(name: String, address: Address)
implicit def addressToJsonObject(addess: Address): JsonObject = {
JsonObject(
"street" -> addess.street,
"number" -> addess.number,
"city" -> addess.city
)
}
implicit def personToJsonObject(person: Person): JsonObject = {
JsonObject(
"name" -> person.name,
"address" -> person.address
)
}
def main(args: Array[String]): Unit = {
val yuval = Person("yuval shavit", Address("rabi merir", 15, "Jerusalem"))
println(serialize(yuval))
// val j = JsonObject(
// JsonField("aaa", 4.8),
// JsonField("bbb", JsonArray(Seq())),
// JsonField("ccc", JsonObject(
// JsonField("ddd", JsonArray(Seq(5, JsonString("bla"))))))
// )
//
// println(j)
// val str = j.toString
//
// var temp = """{"sdsad":[{"yuval":0,"sha vit":1},[2,4]]}"""
//
// val o = JsonObject.parse(JsonTokenizer(temp))
// println(o)
}
}