爲什麼這不起作用?json4s無法用mixin特徵序列化案例類
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對象
{}
而如果我刪除了 「以迎接」 我獲得(正確)結果:
{"id":1,"numbers":[1,2]}