Skip to content

Commit

Permalink
Add test for case classes with self-type
Browse files Browse the repository at this point in the history
  • Loading branch information
plokhotnyuk committed Sep 7, 2024
1 parent fb88ed2 commit 9f652a6
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,30 @@ object Version {
case object `8.09` extends Version("8.9")
}

trait Aggregate {
type Props

implicit def propsCodec: JsonValueCodec[Props]
}

trait Events { self: Aggregate =>
case class MyEvent(props: Props)

// Works here
implicit val myEventCodec: JsonValueCodec[MyEvent] = make
}

object Person extends Aggregate with Events {
case class Props(name: String, age: Int)

implicit val propsCodec: JsonValueCodec[Props] = make

// FIXME: Doesn't work here
// Scala 3: No implicit 'com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec[_ >: scala.Nothing <: scala.Any]' defined for 'Events.this.Props'.
// Scala 2: Only sealed traits or abstract classes are supported as an ADT base. Please consider sealing the 'Events.this.Props' or provide a custom implicitly accessible codec for it.
// val myEventCodec: JsonValueCodec[MyEvent] = make
}

class JsonCodecMakerSpec extends VerifyingSpec {
import com.github.plokhotnyuk.jsoniter_scala.macros.NamespacePollutions._

Expand Down Expand Up @@ -1303,6 +1327,11 @@ class JsonCodecMakerSpec extends VerifyingSpec {
"No implicit 'com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec[_ >: scala.Nothing <: scala.Any]' defined for 'A'."
}))
}
"serialize and deserialize case classes with self-type" in {
import Person._

verifySerDeser(myEventCodec, MyEvent(Props("John", 42)), """{"props":{"name":"John","age":42}}""")
}
"serialize and deserialize case classes with value classes" in {
case class ValueClassTypes(uid: UserId, oid: OrderId)

Expand Down

0 comments on commit 9f652a6

Please sign in to comment.