Reputation: 8504
Code snippet in 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"}
In the output, I want to assign labels to attributes instead of _1
, _2
, _3
. How would I go about doing this?
Upvotes: 4
Views: 2810
Reputation: 60006
Use a case class
instead of a tuple:
case class Named(myInt: Int, thisDouble: Double, desc: String)
generate(Named(1, 3.14, "Fred"))
Gives:
{"myInt": 1.0,"thisDouble":3.14,"desc":"Fred"}
Upvotes: 2