scala - What is a good way to handle default values with spray-json -
in cases default values make more sense optionals in case classes:
case class car(numberofwheels:int = 4, color:string) case class car(numbeofwheels:option[int], color:string) //silly
in first case i'd expect able convert following json instance:
{"color":"red"}
but standard jsonformat2(car)
, spray-json complains missing value numberofwheels
.
how work around cleanly?
i stumbled upon same problem. i've create patch solves me. makes fields default value optional.
https://github.com/spray/spray-json/pull/56
update: pr updated , still open https://github.com/spray/spray-json/pull/93
Comments
Post a Comment