I am trying to write a custom Json serializer in a game for the case class, but I do not want it to serialize all the fields of the class. I am new to Scala, so this is definitely a problem, but this is what I have tried so far:
case class Foo(a: String, b: Int, c: Double)
Now, by default, this is done, as far as I saw in the examples:
implicit val fooWrites: Writes[Foo] = ( (__ \ "a").write[String] and (__ \ "b").write[Int] (__ \ "c").write[Double] ) (unlift(Foo.unapply))
But what if I want to omit c from Json output? I have tried this so far, but it does not compile:
implicit val fooWritesAlt: Writes[Foo] = ( (__ \ "a").write[String] and (__ \ "b").write[Int] ) (unlift({(f: Foo) => Some((fa, fb))}))
Any help is much appreciated!
siki
source share