Skip to content

Avoid throwing errors when a fallback Decoder is bound #1535

@hearnadam

Description

@hearnadam

JsonDecoder.orElse relies on the self.unsafeDecode throwing an exception to continue to the next decoder.
https://github.com/zio/zio-json/blob/series/2.x/zio-json/shared/src/main/scala/zio/json/JsonDecoder.scala#L118-L128

This is likely unnecessarily expensive, as it produces an error that will never be read.

It also doesn't help that orElse accepts the other decoder as a by-name parameter, which can re-instantiate an encoder if users are not careful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions