为什么这不起作用?
object JsonExample extends App {
import org.json4s._
import org.json4s.native.Serialization
import org.json4s.native.Serialization.{read, write}
implicit val formats = Serialization.formats(NoTypeHints)
case class Winner(id: Long, numbers: List[Int])
trait Greet { val greeting = "hi"}
val obj = new Winner(1, List(1,2)) with Greet
println(write(obj))
}
这将打印一个空的 JSON 对象
{}
而如果我删除“with Greet”,我会得到(正确的)结果:
{"id":1,"numbers":[1,2]}