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 fails while decoder succeeds in 0.3.0-RC7 #622

Open
fanf opened this issue Apr 20, 2022 · 5 comments
Open

codec fails while decoder succeeds in 0.3.0-RC7 #622

fanf opened this issue Apr 20, 2022 · 5 comments
Assignees
Labels
Active bug Something isn't working derivation

Comments

@fanf
Copy link
Contributor

fanf commented Apr 20, 2022

When trying to test upgrade to ZIO 2.0, I discovered that a codec that was correctly decoding JSON with zio-json 2.0.0-M3 is now failing with 3.0.0-RC7.
Even weirder, the decoding starts to work if I remove the encoder from the codec (and only keeps the decoder).

A minimization of the problem is available here: https://gist.github.com/fanf/8e77ffcb6af1be02670338254356135d

@fanf fanf changed the title codec fails while decoder succeed in 3.0.0-RC7 codec fails while decoder succeeds in 3.0.0-RC7 Apr 20, 2022
@fsvehla fsvehla changed the title codec fails while decoder succeeds in 3.0.0-RC7 codec fails while decoder succeeds in 0.3.0-RC7 May 10, 2022
@fsvehla
Copy link
Contributor

fsvehla commented May 10, 2022

Thanks for the minimization, @fanf. I can confirm that something’ going on here and I’m working on it.

@fsvehla fsvehla self-assigned this May 10, 2022
@fsvehla fsvehla added bug Something isn't working derivation Active labels May 10, 2022
@fsvehla
Copy link
Contributor

fsvehla commented May 17, 2022

@fanf It looks to me that JsonCodec derivation isn’t considering JsonDecoders inside of other codecs when recursively deriving JsonDecoders.

The most minimal workaround is to also a JsonDecoder for each derived JsonCodec.
In line :29 of your example

implicit lazy val eitherListOrValueDecoder: JsonDecoder[Either[List[String], JsonExpectedValueId7_1]] =
  codecJsonEitherValue.decoder

I’m not yet sure about how to fix this properly.
Let me know if this workaround ↑ helps you.

@fanf
Copy link
Contributor Author

fanf commented May 17, 2022

I will try, thanks. What is suprising is that it used to work in ZIO 1.0

@fanf
Copy link
Contributor Author

fanf commented Jun 8, 2022

@fsvehla sorry for the delay, I was finally able to test your workaround and I can confirm that always using a pair of encode, decoder in place of a codec leads to the previous correct result.
It's boilterplaty (well, two times more than previous boilerplate) but I least I can go on.

@fsvehla
Copy link
Contributor

fsvehla commented Jun 9, 2022

Thanks for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Active bug Something isn't working derivation
Projects
None yet
Development

No branches or pull requests

2 participants