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

Formatters for an ADT needs to be placed after all instances #42

Open
alexbergeron opened this issue Jan 10, 2017 · 1 comment
Open

Comments

@alexbergeron
Copy link

The following code fails to compile with a could not find Lazy implicit value of type julienrf.json.derived.DerivedReads[A]:

import julienrf.json.derived
import play.api.libs.json._

sealed trait Minimize

object Minimize {
  implicit val formats: OFormat[Minimize] = derived.flat.oformat((__ \ "type").format[String])
}

case class MinimizeA(a: String) extends Minimize

case class MinimizeB(b: Int) extends Minimize

The following code compiles successfully:

import julienrf.json.derived
import play.api.libs.json._

sealed trait Minimize

case class MinimizeA(a: String) extends Minimize

case class MinimizeB(b: Int) extends Minimize

object Minimize {
  implicit val formats: OFormat[Minimize] = derived.flat.oformat((__ \ "type").format[String])
}

As there is a workaround, this is not a critical bug, but it felt like a "gotcha" moment.

@julienrf
Copy link
Owner

If I remember well it’s a limitation of knownDirectSubclasses. I think this PR scala/scala#5284 fixed the issue, though. Are you using Scala 2.12?

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

No branches or pull requests

2 participants