Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflow after migration to 10.0.1 from 9.0.0 #84

Closed
plokhotnyuk opened this issue May 13, 2021 · 3 comments · Fixed by #85
Closed

Stack overflow after migration to 10.0.1 from 9.0.0 #84

plokhotnyuk opened this issue May 13, 2021 · 3 comments · Fixed by #85

Comments

@plokhotnyuk
Copy link

plokhotnyuk commented May 13, 2021

Here is a code snippet that works fine using 9.0.0 but fails with stack overflow using 10.0.1:

import julienrf.json.derived.flat
import play.api.libs.functional.syntax._
import play.api.libs.json._

sealed trait ADTBase extends Product with Serializable
case class X(a: Int) extends ADTBase
case class Y(b: String) extends ADTBase
case class Z(l: ADTBase, r: ADTBase) extends ADTBase

val adtFormat: Format[ADTBase] = {
  implicit lazy val v1: Format[X] = Json.format
  implicit lazy val v2: Format[Y] = Json.format
  implicit lazy val v3: Format[Z] = Json.format
  implicit lazy val v4: Format[ADTBase] = flat.oformat((__ \ "type").format[String])
  v4
}

println(Json.parse("""{"type":"Z","l":{"type":"X","a":1},"r":{"type":"Y","b":"VVV"}}""").as[ADTBase](adtFormat))

Link to Scastie: https://scastie.scala-lang.org/WIYG5my6TNyIYF8zsWIkCg

@julienrf
Copy link
Owner

@ncreep would you be interested in having a look?

@ncreep
Copy link
Contributor

ncreep commented May 13, 2021

Recursion my old friend...

Will take a look.

@ncreep
Copy link
Contributor

ncreep commented May 13, 2021

Opened a pull request with the fix: #85.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants