Skip to content

Commit 15a8aa4

Browse files
Invalid type consistency
1 parent e87b565 commit 15a8aa4

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

zio-json/shared/src/test/scala/zio/json/DecoderSpec.scala

+30
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,36 @@ object DecoderSpec extends ZIOSpecDefault {
427427
assert(decoder.fromJsonAST(jsonString.fromJson[Json].getOrElse(Json.Null)))(
428428
isLeft(equalTo("Missing fields: v2, v3"))
429429
)
430+
},
431+
test("invalid type consistency") {
432+
case class C(
433+
v1: String
434+
)
435+
436+
object C {
437+
implicit val cDecoder: JsonDecoder[C] = DeriveJsonDecoder.gen[C]
438+
}
439+
440+
case class B(c: C)
441+
442+
object B {
443+
implicit val bDecoder: JsonDecoder[B] = DeriveJsonDecoder.gen[B]
444+
}
445+
446+
case class A(b: B)
447+
448+
object A {
449+
implicit val aDecoder: JsonDecoder[A] = DeriveJsonDecoder.gen[A]
450+
}
451+
452+
val jsonString = Json.Obj("b" -> Json.Obj("c" -> Json.Obj("v1" -> Json.Num(15)))).toJson
453+
454+
val decoder = JsonDecoder[A]
455+
456+
assert(decoder.decodeJson(jsonString))(isLeft(equalTo(".b.c.v1(expected '\"' got '1')"))) &&
457+
assert(decoder.fromJsonAST(jsonString.fromJson[Json].getOrElse(Json.Null)))(
458+
isLeft(equalTo("Not a string value"))
459+
)
430460
}
431461
)
432462
)

0 commit comments

Comments
 (0)