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

Add JsonCodec derivation from encoder and decoder #1115

Merged
merged 2 commits into from
May 17, 2024

Conversation

guersam
Copy link
Contributor

@guersam guersam commented May 14, 2024

Currently summon[JsonCodec[zio.json.ast.Json]] fails even though there are implicit encoder and decoder.

This PR allows codec derivation for types that already have encoder and decoder, in the same way of the current collection codec derivation.

@guersam guersam requested a review from a team as a code owner May 14, 2024 07:06
@@ -190,4 +188,6 @@ private[json] trait CodecLowPriority3 { this: JsonCodec.type =>
implicit val uuid: JsonCodec[java.util.UUID] = JsonCodec(JsonEncoder.uuid, JsonDecoder.uuid)

implicit val currency: JsonCodec[java.util.Currency] = JsonCodec(JsonEncoder.currency, JsonDecoder.currency)

implicit def fromEncoderDecoder[A](implicit encoder: JsonEncoder[A], decoder: JsonDecoder[A]): JsonCodec[A] = new JsonCodec(encoder, decoder)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the name from apply because it conflicts with the autogenerated apply function for case class JsonCodec.

@guersam guersam force-pushed the codec-from-encoder-decoder branch from e986ee6 to ef21ec3 Compare May 14, 2024 07:08
@guersam
Copy link
Contributor Author

guersam commented May 14, 2024

There's a problem with Scala 2.12 🤔 Is it acceptable to provide the derivation for 2.13 or above only?

@jdegoes
Copy link
Member

jdegoes commented May 15, 2024

@guersam Yes, that's acceptable.

@guersam guersam requested a review from jdegoes May 17, 2024 02:55
@fsvehla fsvehla merged commit 8617060 into zio:series/2.x May 17, 2024
28 checks passed
@guersam guersam deleted the codec-from-encoder-decoder branch May 17, 2024 12:31
ThijsBroersen pushed a commit to ThijsBroersen/zio-json that referenced this pull request Jun 13, 2024
* Add JsonCodec derivation from encoder and decoder
* Disable JsonCodec derivaton from encoder & decoder for Scala 2.12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants