Skip to content
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

Codec.from changes decoder behaviour #2104

Open
jakubdaniel opened this issue Feb 27, 2023 · 2 comments
Open

Codec.from changes decoder behaviour #2104

jakubdaniel opened this issue Feb 27, 2023 · 2 comments

Comments

@jakubdaniel
Copy link

Assuming

val e = io.circe.Encoder.instance[Option[Int]] { _ => ??? } // fake, not used in this example
val d = io.circe.Decoder.decodeOption[Int]
val c = io.circe.Codec.from(d, e)
val h = io.circe.Json.obj().hcursor

is

scala> d.at("x").tryDecode(h)
val res0: io.circe.Decoder.Result[Option[Int]] = Right(None)

scala> c.at("x").tryDecode(h)
val res1: io.circe.Decoder.Result[Option[Int]] = Left(DecodingFailure at .x: Missing required field)

expected?

I'd expect c to behave exactly as d on all inputs to any of the Decoder methods. But it obviously doesn't. This is because it falls back to the default implementations of tryDecode etc instead of properly delegating all the methods to any potential overrides already baked into d.

@zarthross
Copy link
Member

Looks to me like the Codec.from method only overrides the 2 abstract methods from Encoder and Decoder, but in reality, we override various other methods from Encoder/Decoder all the time... we need to update that Codec.from implementation (and any other implementations of Codec for that matter) so that it correctly proxies ALL methods to the correct underlying Encoder/Decoder

@satorg
Copy link
Contributor

satorg commented May 30, 2024

It seems, this one was resolved via #2131 , wasn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants