zio-json
zio-json copied to clipboard
JsonDecoder.{zip, zipRight, ...} don't preserve their laziness
As discussed on discord:
Even though zip
, zipLeft
, zipRight
and zipWith
on JsonDecoder
all take their second decoder by name, they internally delegate to JsonDecoder.tuple2
. This renders them effectively non-lazy.
Here is an example of code which one might expect to work but which throws a stack overflow error:
import zio.json.*
final case class Tree(value: Int, children: List[Tree])
object Tree:
implicit def decoder: JsonDecoder[Tree] =
JsonDecoder[Int].zipWith(JsonDecoder.list(decoder))(Tree.apply)
@main()
def run =
println("[1, [[2, []]]]".fromJson[Tree])