Skip to content

Scala 3 case object derivation differs from Scala 2 #1482

Description

@hearnadam

The following code produces differing JSON outputs on Scala 2 and 3:

import zio.json._

sealed trait Parent
object Parent {
  case object Child extends Parent
  def child: Parent = Child
  implicit val codec: JsonCodec[Parent] = DeriveJsonCodec.gen
}

println(Parent.child.toJson)

Scala 2: {"Child":{}}
Scala 3: "Child"

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions