-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
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
zio.json.ast.Json.as[X] does not support nullable/Option fields #710
Comments
It seems ok like this (using last RC) : import zio.json._
case class SomeClass(a: Int, b: Option[String])
object SomeClass :
given JsonCodec[SomeClass] = DeriveJsonCodec.gen[SomeClass]
val start = SomeClass(1, None)
println(start)
val back = start.toJson
println(back)
println(back.fromJson[SomeClass]) Prints: SomeClass(1,None) |
@loicdescotte Your test does not extract/map/deserialize from the json ast. The issue is still there in the current/latest RC ( you can verify this yourself by simply adding the last two lines of this to your own test code: import zio.json._
case class SomeClass(a: Int, b: Option[String])
object SomeClass:
given JsonCodec[SomeClass] = DeriveJsonCodec.gen[SomeClass]
val start = SomeClass(1, None)
println(start)
val back = start.toJson
println(back)
println(back.fromJson[SomeClass])
val backAst = start.toJsonAST
println(backAst.flatMap(_.as[SomeClass])) // fails |
I ended up having a similar problem, but only in Scala 3, according to the syntax you used I guess this is you case too, #781 should solve that |
@GiGurra @loicdescotte @ex0ns Is this fixed now? |
https://github.com/zio/zio-json/blob/series/2.x/zio-json/shared/src/test/scala/zio/json/DecoderSpec.scala#L130 is still passing so I guess it does, I have to say that I don't even remember why I needed that or if I even used it after fixing, but in theory, that should work |
@fsvehla I think we can close this issue |
ast Json
as
method does not respect nullable fields. Instead of decoding to option it produces decoding error.Example:
Prints
The text was updated successfully, but these errors were encountered: