File tree 1 file changed +30
-0
lines changed
zio-json/shared/src/test/scala/zio/json
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -427,6 +427,36 @@ object DecoderSpec extends ZIOSpecDefault {
427
427
assert(decoder.fromJsonAST(jsonString.fromJson[Json ].getOrElse(Json .Null )))(
428
428
isLeft(equalTo(" Missing fields: v2, v3" ))
429
429
)
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
+ )
430
460
}
431
461
)
432
462
)
You can’t perform that action at this time.
0 commit comments