Skip to content

Commit

Permalink
Testcase showing difference in ADT encoding between scala 2 and 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaechler committed Feb 11, 2025
1 parent 2a0c55a commit c6ac130
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions zio-json/shared/src/test/scala/zio/json/CodecSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ object CodecSpec extends ZIOSpecDefault {
assert("""{"s":""}""".fromJson[OnlyString])(isRight(equalTo(OnlyString("")))) &&
assert("""{"s":"","t":""}""".fromJson[OnlyString])(isLeft(equalTo("(invalid extra field)")))
},
test("sum of objects encoding") {
import examplesumofobjects._

assert("""{"Child1":{}}""".fromJson[Parent])(isRight(equalTo(Child1))) &&
assert("""{"Child2":{}}""".fromJson[Parent])(isRight(equalTo(Child2))) &&
assert("""{"type":"Child1"}""".fromJson[Parent])(isLeft(equalTo("(invalid disambiguator)")))
},
test("sum encoding") {
import examplesum._

Expand Down Expand Up @@ -243,6 +250,16 @@ object CodecSpec extends ZIOSpecDefault {
}
}

object examplesumofobjects {
sealed abstract class Parent

object Parent {
implicit val codec: JsonCodec[Parent] = DeriveJsonCodec.gen[Parent]
}
case object Child1 extends Parent
case object Child2 extends Parent
}

object examplesum {
sealed abstract class Parent

Expand Down

0 comments on commit c6ac130

Please sign in to comment.