Skip to content

None is written as null with Include.NON_NULL set since 2.7.4 (also another issue with 2.7.3 and earlier) #325

@dimatkach

Description

@dimatkach

case class Foo(bar: Options[String] = None)
gets written as { "bar": null }.
This used to work for me before (at least, in 2.6.6). Not sure at which point it got broken, I ran into this issue trying to upgrade to 2.8.8.

Update: Looks like the last version it works right is 2.7.3. I haven't checked everything after that, but 2.7.{4,5,9} and 2.8.0 are all broken.

Unfortunately, I cannot use 2.7.3 or 2.7.2, because they have another issue (seems to be gone in 2.8.8, so I am not reporting it separately): if I have a trait extending a Product, and a case class with a field, that's Option of that trait, then serializing that case class always writes that field as empty:

   trait Prod extends Produc1[String] { def x: String; def canEqual(o: Any) = ???; def _1 = x }
   class Foo(val x: String) extends Prod
   case class Bar(bar: Prod)
   case class Bat(bam: Option[Foo])
   case class Baz(baz: Option[Prod])

   mapper.writeValueAsString(new Foo("bar")) // { "x" = "bar" } - good
   mapper.writeValueAsString(Bar(new Foo("bar"))) // { "bar" = { "x" = "bar" }} - good
   mapper.writeValueAsString(Bat(Some(new Foo("bar")))) // { "bat" = { "x" = "bar" }} - good
   mapper.writeValueAsString(Baz(Some(new Foo("bar")))) // { "baz" = {}} - ????

So, it looks like I am stuck with 2.6.6. for now ... :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions