Open Iltotore opened 1 year ago
Actually there is an equivalent: https://zio.github.io/zio-prelude/docs/functionaldatatypes/validation.
validation could be the implementation but with the decoder that fail on first will not help the case
This is only the default implementation to not force users to make an accumulative and non-accumulative implementation for their Decoder. AFAIK decodeJsonAccumulating
is overriden in Circe's Decoder for objects with an implementation that actually makes use of error accumulation.
Accumulating error enables to get and return all occured errors during Json decoding:
This is especially useful for form-like/API validation. This can be compared to Circe's
decodeAccumulating
or Cats'Validated
.As far as I know, there's no
Validated
equivalent for ZIO/ZIO Prelude but anEither[List[String], A]
would be enough.For example, I would like my above example to return
Left(List(".name(...)", ".age(...)"))
.In Circe, this is achieved by defining a second method in the
Decoder
(in ZIO-JSON,JsonDecoder
) typeclass nameddecodeAccumulating
which could be nameddecodeJsonAccumulating
to feel more consistent with the existingdecodeJson
method.To preserve retrocompatibility and because sometimes it's non sense to use error accumulation, the method can be defined like this by default: