Open anton0xf opened 5 months ago
It is even works well if I don't mention "a"
fielld:
case class Foo(a: Option[Int])
implicit val fooReader: JsonReader[Foo] = jsonReader[Foo] {
ReaderBuilder[Foo]
.extract(_.a)
.from("c".as[Option[Int]], "b".as[Option[Int]])((c, b) => c.orElse(b))
}
println("""{"b": 2}""".jsonAs[Foo]) // => Right(Foo(Some(2)))
println("""{"c": 2}""".jsonAs[Foo]) // => Right(Foo(Some(2)))
Thanks for reporting! That's indeed looks like a bug
I can read field value from one of two JSON-fields with code like this (and it works well):
Playground
But the same approach doesn't work if
a
isOption
:Playground
Is it a bug or my misunderstanding?
I tested it on 0.28.3 and some older versions