Scala Play Json format macro - write Option as null by default

15 views
Skip to first unread message

Raphael André Bauer

unread,
Jan 23, 2018, 10:30:26 AM1/23/18
to play-fr...@googlegroups.com
Hi,


I am wondering whether there is a clever way to globally tell Scala
Play Json to render
Option values as nulls by default (and not omitting them) when using
the format macro.

Example:
case class MyDto(name: String, city: Option[String])
object MyDto {
implicit val myDtoFormat = Json.format[MyDto]
}

That will happily read null values when we parse a json with nulls,
but it will not render 'city' via json, when
it is null on Scala side.

I could just define a transformer to do the stuff (aka using
write[Option[String]]).
But I was wondering whether there is already something built-in I missed.
Something global. JsonConfiguration or similar.


Thanks!


Raphael
Reply all
Reply to author
Forward
0 new messages