Skip to content

Commit

Permalink
Annotations on Transform have effects on inner schema for Json Codec (#…
Browse files Browse the repository at this point in the history
…604)

Co-authored-by: Daniel Vigovszky <daniel.vigovszky@gmail.com>
  • Loading branch information
987Nabil and vigoo authored Sep 6, 2023
1 parent 1a9ab2b commit a1d38fc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ object JsonCodec {
case Schema.Map(ks, vs, _) => mapEncoder(ks, vs, discriminatorTuple)
case Schema.Set(s, _) =>
ZJsonEncoder.chunk(schemaEncoder(s, discriminatorTuple)).contramap(m => Chunk.fromIterable(m))
case Schema.Transform(c, _, g, _, _) => transformEncoder(c, g)
case Schema.Transform(c, _, g, a, _) => transformEncoder(a.foldLeft(c)((s, a) => s.annotate(a)), g)
case Schema.Tuple2(l, r, _) => ZJsonEncoder.tuple2(schemaEncoder(l, discriminatorTuple), schemaEncoder(r, discriminatorTuple))
case Schema.Optional(schema, _) => ZJsonEncoder.option(schemaEncoder(schema, discriminatorTuple))
case Schema.Fail(_, _) => unitEncoder.contramap(_ => ())
Expand Down Expand Up @@ -490,7 +490,7 @@ object JsonCodec {
case Schema.Primitive(standardType, _) => primitiveCodec(standardType).decoder
case Schema.Optional(codec, _) => ZJsonDecoder.option(schemaDecoder(codec, hasDiscriminator))
case Schema.Tuple2(left, right, _) => ZJsonDecoder.tuple2(schemaDecoder(left, hasDiscriminator), schemaDecoder(right, hasDiscriminator))
case Schema.Transform(codec, f, _, _, _) => schemaDecoder(codec, hasDiscriminator).mapOrFail(f)
case Schema.Transform(c, f, _, a, _) => schemaDecoder(a.foldLeft(c)((s, a) => s.annotate(a)), hasDiscriminator).mapOrFail(f)
case Schema.Sequence(codec, f, _, _, _) => ZJsonDecoder.chunk(schemaDecoder(codec, hasDiscriminator)).map(f)
case Schema.Map(ks, vs, _) => mapDecoder(ks, vs, hasDiscriminator)
case Schema.Set(s, _) => ZJsonDecoder.chunk(schemaDecoder(s, hasDiscriminator)).map(entries => entries.toSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import zio.schema.{ DynamicValue, Schema, StandardType, TypeId }

package object json {
implicit val schemaJson: Schema[Json] =
Schema.dynamicValue.annotate(directDynamicMapping()).transform(toJson, fromJson)
Schema.dynamicValue.transform(toJson, fromJson).annotate(directDynamicMapping())

private def toJson(dv: DynamicValue): Json =
dv match {
Expand Down

0 comments on commit a1d38fc

Please sign in to comment.