In some cases default values make more sense than optionals in case classes:
case class Car(numberOfWheels:Int = 4, color:String)
case class Car(numbeOfWheels:Option[Int], color:String) //silly
In the first case I'd expect to be able to easily convert the following json to an instance:
{"color":"red"}
But with a standard jsonFormat2(Car)
, spray-json complains about missing value for numberOfWheels
.
How do I work around this most cleanly?