In playframework:
import play.api.libs.json._
val obj = Json.obj(
"aaa" -> 111,
"bbb" -> Some(222)
)
println(obj.toString)
Which outputs:
{"aaa":111,"bbb":222}
But if I change the code to:
val obj = Json.obj(
"aaa" -> 111,
"bbb" -> None
)
It can't be compiled, and reports:
Error:(6, 17) diverging implicit expansion for type play.api.libs.json.Writes[None.type]
starting with method OptionWrites in trait DefaultWrites
"bbb" -> None
^
How to fix it?