I have a case class like this:
case class TotalTest(f1: Option[String], f2: Option[String], f3: String)
Using Gson
, I am trying to write the contents into a Json file, here's what I get:
val test1 = (new Gson).toJson(TotalTest(Some("a"), Some("b"), "c"))
val pw1 = new PrintWriter(new File("test1.json" ))
pw1.write(test1)
pw1.close
The contents would be:
{"f1":{},"f2":{},"f3":"c"}
Why would I lose the first two fields? Basically I have a highly nested object of a case class with a lots of Option
s and am wondering an easy way to extract the results.