REPL
scala> import com.codahale.jerkson.Json._
scala> val t = (1, 3.14, "Fred")
scala> generate(t)
res5: String = {"_1":1,"_2":3.14,"_3":"Fred"}
在输出中,我想为属性而不是_1
,_2
,_3
分配标签。我该怎么做呢?
答案 0 :(得分:3)
使用case class
代替元组:
case class Named(myInt: Int, thisDouble: Double, desc: String)
generate(Named(1, 3.14, "Fred"))
给出:
{"myInt": 1.0,"thisDouble":3.14,"desc":"Fred"}