是否可以让半自动解码器考虑案例类字段的默认值?
以下代码将失败:
Left(DecodingFailure(Attempt to decode value on failed cursor, List(DownField(isActive))))
我认为 circe 会考虑案例类字段的默认值isActive
case class Person(
id: Option[Int] = None,
name: String,
isActive: Boolean = true
)
implicit val personJsonDecoder: Decoder[Person] = deriveDecoder
val rawJson = """
{
"name": "Geovanny Junio"
}
"""
val r = for {
j <- parse(rawJson)
p <- j.as[Person]
} yield p
println(r)