circe
circe copied to clipboard
Error is not correctly displayed for nested objects starting from 0.14.3
I noticed that the error message is sometimes incorrect when decoding nested objects.
package org.my
import cats.implicits._
import io.circe.Decoder
import io.circe.parser.decode
import io.circe.generic.semiauto.deriveDecoder
object MyMain extends App {
case class Location(city: String)
case class Person(name: String, location: Location)
val jsonString =
"""{
| "name": "John",
| "location": {
| }
|}""".stripMargin
implicit val decoder: Decoder[Person] = deriveDecoder[Person]
val result = decode[Person](jsonString)
println(result)
println(result.left.map(_.show))
}
For 0.14.2 it works as expected because it's clear where the missing property comes from (i.e. .location.city
):
Left(DecodingFailure(Missing required field, List(DownField(city), DownField(location))))
Left(DecodingFailure at .location.city: Missing required field)
For 0.14.3 it doesn't work as expected as the root (.location
) seems to be missing only in the .show
:
Left(DecodingFailure(Missing required field, List(DownField(city), DownField(location))))
Left(DecodingFailure at .city: Missing required field)
For 0.14.4 and 0.14.5 the output is as follows where both miss the root object (i.e. .location
):
Left(DecodingFailure at .city: Missing required field)
Left(DecodingFailure at .city: Missing required field)