We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I can read field value from one of two JSON-fields with code like this (and it works well):
import tethys._ import tethys.jackson._ import tethys.derivation.builder._ import tethys.derivation.semiauto._ case class Foo(a: Int) implicit val fooReader: JsonReader[Foo] = jsonReader[Foo] { ReaderBuilder[Foo] .extract(_.a) .from("a".as[Option[Int]], "b".as[Option[Int]])((a, b) => a.orElse(b) .getOrElse(throw new RuntimeException("cannot find 'a' or 'b'")) ) } println("""{"b": 2}""".jsonAs[Foo]) // => Right(Foo(2))
Playground
But the same approach doesn't work if a is Option:
a
Option
// same imports case class Foo(a: Option[Int]) implicit val fooReader: JsonReader[Foo] = jsonReader[Foo] { ReaderBuilder[Foo] .extract(_.a) .from("a".as[Option[Int]], "b".as[Option[Int]])((a, b) => a.orElse(b)) } println("""{"b": 2}""".jsonAs[Foo]) // => Right(Foo(None)) // but expected // => Right(Foo(2))
Is it a bug or my misunderstanding?
I tested it on 0.28.3 and some older versions
The text was updated successfully, but these errors were encountered:
It is even works well if I don't mention "a" fielld:
"a"
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)))
Sorry, something went wrong.
Thanks for reporting! That's indeed looks like a bug
Considering fix only for scala 3
No branches or pull requests
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
The text was updated successfully, but these errors were encountered: