zio-json icon indicating copy to clipboard operation
zio-json copied to clipboard

Option field appears as null in serialized json when importing io.json.JsonCodec._

Open fanf opened this issue 4 years ago • 0 comments

There is a behavior change between zio-json 0.1 and 0.1.1: if you have import zio.json.JsonCodec._ in scope, then Option fields of case classes are displayed as null when None, so that:

case class Foo(opt: Option[String], name: String)
implicit val encFoo = DeriveJsonEncoder.gen[Foo]
Foo(None, "name").toJson // {"opt":null,"name":"name"}

https://scastie.scala-lang.org/Qrzx9jmqTsCNpNsfoytlVg

fanf avatar Jul 30 '21 20:07 fanf