I am having cases classes with a lot of Option[] values. When I serialize these classes all None values get mapped to "somename":null. This results in unnecessary big Json structurer.
An example is already in the
docs:
val zombie = Creature("zombie", true, 100.0F, "sh...@dead.com", ("ain", 2), List(gizmo), None) val zombiejs = Json.toJson(zombie)
zombiejs: play.api.libs.json.JsValue = {"name":"zombie","isDead":true,"weight":100.0,"email":"sh...@dead.com","favorites":{"string":"ain","number":2},"friends":[{"name":"gremlins","isDead":false,"weight":1.0,"email":"gi...@midnight.com","favorites":{"string":"alpha","number":85},"friends":[],"social":"@gizmo"}],"social":null
As you see, the social field (last in the Creature case class), which is None, results in a "social":null output.
Is there any way to suppress that (Jackson object mapper has an option for that)? I don't want to see the nulls ... following Pascals post in a
different thread:
I advise not to use null for a missing field in JSON. null is a valid value in JSON (mapped to JsNull in Play).