Skip to content

Commit

Permalink
fix(JsonCodec): codec derivation on nested types
Browse files Browse the repository at this point in the history
  • Loading branch information
ifndev committed Jul 29, 2024
1 parent 6d2abd4 commit 82073e0
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 12 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 3 additions & 0 deletions zio-json/shared/src/main/scala/zio/json/JsonCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 82073e0

Please sign in to comment.