Skip to content

Commit 444e831

Browse files
decodeJson vs fromJsonAST error consistency
1 parent c2b7776 commit 444e831

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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

+33
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,39 @@ object DecoderSpec extends ZIOSpecDefault {
395395
assert(bad5.as[UUID])(isLeft(containsString("Invalid UUID: 64d7c38d-2afd-XXXX-9832-4e70afe4b0f8"))) &&
396396
assert(bad6.as[UUID])(isLeft(containsString("Invalid UUID: 64d7c38d-2afd-X-9832-4e70afe4b0f8"))) &&
397397
assert(bad7.as[UUID])(isLeft(containsString("Invalid UUID: 0-0-0-0-00000000000000000")))
398+
},
399+
test("consistency") {
400+
case class C(
401+
v1: String,
402+
v2: String,
403+
v3: String
404+
)
405+
406+
object C {
407+
implicit val cDecoder: JsonDecoder[C] = DeriveJsonDecoder.gen[C]
408+
}
409+
410+
case class B(c: C)
411+
412+
object B {
413+
implicit val bDecoder: JsonDecoder[B] = DeriveJsonDecoder.gen[B]
414+
}
415+
416+
case class A(b: B)
417+
418+
object A {
419+
implicit val aDecoder: JsonDecoder[A] = DeriveJsonDecoder.gen[A]
420+
}
421+
422+
val jsonString = Json.Obj("b" -> Json.Obj("c" -> Json.Obj("v1" -> Json.Str("value")))).toJson
423+
424+
val decoder = JsonDecoder[A]
425+
426+
assert(decoder.decodeJson(jsonString))(isLeft(equalTo(".b.c.v2(missing)")))
427+
428+
assert(decoder.fromJsonAST(jsonString.fromJson[Json].getOrElse(Json.Null)))(
429+
isLeft(equalTo("Missing fields: v2, v3"))
430+
)
398431
}
399432
)
400433
)

0 commit comments

Comments
 (0)