From 82073e06e653e691fdb607c1b65daef3552f93cc Mon Sep 17 00:00:00 2001 From: "Patrick D. Conti" Date: Mon, 29 Jul 2024 15:05:35 +0200 Subject: [PATCH] fix(JsonCodec): codec derivation on nested types --- .../scala-2.12/zio/json/JsonCodecVersionSpecific.scala | 3 --- .../scala-2.13/zio/json/JsonCodecVersionSpecific.scala | 7 ------- .../main/scala-3/zio/json/JsonCodecVersionSpecific.scala | 2 -- zio-json/shared/src/main/scala/zio/json/JsonCodec.scala | 3 +++ 4 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 zio-json/shared/src/main/scala-2.12/zio/json/JsonCodecVersionSpecific.scala delete mode 100644 zio-json/shared/src/main/scala-2.13/zio/json/JsonCodecVersionSpecific.scala diff --git a/zio-json/shared/src/main/scala-2.12/zio/json/JsonCodecVersionSpecific.scala b/zio-json/shared/src/main/scala-2.12/zio/json/JsonCodecVersionSpecific.scala deleted file mode 100644 index e57d1dc3..00000000 --- a/zio-json/shared/src/main/scala-2.12/zio/json/JsonCodecVersionSpecific.scala +++ /dev/null @@ -1,3 +0,0 @@ -package zio.json - -private[json] trait JsonCodecVersionSpecific diff --git a/zio-json/shared/src/main/scala-2.13/zio/json/JsonCodecVersionSpecific.scala b/zio-json/shared/src/main/scala-2.13/zio/json/JsonCodecVersionSpecific.scala deleted file mode 100644 index f3292ed1..00000000 --- a/zio-json/shared/src/main/scala-2.13/zio/json/JsonCodecVersionSpecific.scala +++ /dev/null @@ -1,7 +0,0 @@ -package zio.json - -private[json] trait JsonCodecVersionSpecific { - - implicit def fromEncoderDecoder[A](implicit encoder: JsonEncoder[A], decoder: JsonDecoder[A]): JsonCodec[A] = - JsonCodec(encoder, decoder) -} diff --git a/zio-json/shared/src/main/scala-3/zio/json/JsonCodecVersionSpecific.scala b/zio-json/shared/src/main/scala-3/zio/json/JsonCodecVersionSpecific.scala index 9b031970..4d309c80 100644 --- a/zio-json/shared/src/main/scala-3/zio/json/JsonCodecVersionSpecific.scala +++ b/zio-json/shared/src/main/scala-3/zio/json/JsonCodecVersionSpecific.scala @@ -3,6 +3,4 @@ package zio.json private[json] trait JsonCodecVersionSpecific { inline def derived[A: deriving.Mirror.Of]: JsonCodec[A] = DeriveJsonCodec.gen[A] - given fromEncoderDecoder[A](using encoder: JsonEncoder[A], decoder: JsonDecoder[A]): JsonCodec[A] = - JsonCodec(encoder, decoder) } diff --git a/zio-json/shared/src/main/scala/zio/json/JsonCodec.scala b/zio-json/shared/src/main/scala/zio/json/JsonCodec.scala index fdad66d1..7034775b 100644 --- a/zio-json/shared/src/main/scala/zio/json/JsonCodec.scala +++ b/zio-json/shared/src/main/scala/zio/json/JsonCodec.scala @@ -87,6 +87,9 @@ final case class JsonCodec[A](encoder: JsonEncoder[A], decoder: JsonDecoder[A]) object JsonCodec extends GeneratedTupleCodecs with CodecLowPriority0 with JsonCodecVersionSpecific { def apply[A](implicit jsonCodec: JsonCodec[A]): JsonCodec[A] = jsonCodec + implicit def fromEncoderDecoder[A](encoder: JsonEncoder[A], decoder: JsonDecoder[A]): JsonCodec[A] = + JsonCodec(encoder, decoder) + private def orElseEither[A, B](A: JsonCodec[A], B: JsonCodec[B]): JsonCodec[Either[A, B]] = JsonCodec( JsonEncoder.orElseEither[A, B](A.encoder, B.encoder),