Say I define the following case classes:
case class A(i: Int)
case class B(str: String)
case class T(a: A, b: B)
I then convert to json, parse back and try to convert again as follows:
val json = write(T(A(1), B("One")))
val parsed = JSON.parse(json).asInstanceOf[js.Dictionary[js.Any]].toMap
println("Json: " + json)
parsed.foreach { case (k, v) =>
println(s"$k: ${v.toString}")
println("Stringify: " + JSON.stringify(v, js.Array[js.Any]()))
}
I get the following output:
Json: {"a":{"i":1},"b":{"str":"One"}}
a: [object Object]
Stringify: {}
b: [object Object]
Stringify: {}
Why does neither toString nor stringify correctly convert the objects back to json?