Spray-Json: serialize None as null
问题 I am porting a rest API to scala, using akka-http with spray-json. The old API had the following response: { "result": { ... }, "error": null } Now I want to maintain exact backwards compatibility, so when there's no error I want an error key with a null value. However I can't see any support for this in spray-json. When I serialize the following with a None error: case class Response(result: Result, error: Option[Error]) I end up with { "result": { ... } } And it completely drops the error