2

After upgrading play-json to 2.7.0 I've started facing a runtime error:

[info] com.mycompany.controllers.HealthControllerSpec *** ABORTED ***
[info]   java.lang.NoSuchMethodError: play.api.libs.json.JsonConfiguration$.apply$default$2()Lplay/api/libs/json/OptionHandlers;
[info]   at com.mycompany.util.json.SnakeCase.$init$(SnakeCase.scala:41)
[info]   at com.mycompany.util.playframework.controllers.HealthView$.<init>(HealthView.scala:15)
[info]   at com.mycompany.util.playframework.controllers.HealthView$.<clinit>(HealthView.scala)
[info]   at com.mycompany.util.playframework.controllers.HealthController.<init>(HealthController.scala:25)
[info]   at com.mycompany.util.playframework.controllers.HealthControllerSpec.$anonfun$new$2(HealthControllerSpec.scala:30)
[info]   at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
[info]   at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
[info]   at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
[info]   at org.scalatest.Transformer.apply(Transformer.scala:22)
[info]   at org.scalatest.Transformer.apply(Transformer.scala:20)

Could anyone point me to reason?

HealthView:

case class HealthView(app: String, description: String, version: Option[String])

object HealthView extends SnakeCase {

  def apply(config: Configuration): HealthView =
    HealthView(
      config.get[String]("app.name"),
      config.get[String]("app.description"),
      config.getOptional[String]("app.version")
    )

  implicit val format: OFormat[HealthView] = Json.format[HealthView]

}

SnakeCase:

trait SnakeCase {

  implicit val jsonConfig: Aux[Json.MacroOptions] = JsonConfiguration(SnakeCaseNaming)

}

Release with minor version should be binary compatible.

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
  • I've seen similar issues in the past. The issue is the json parsing isn't working. Most likely something in the implicit doesn't work. Could you perhaps try use the validate method? Like this json.validate[MyObject] – GamingFelix Feb 08 '19 at 13:36
  • 1
    @GamingFelix I think this won't help, because I am having JVM error (`java.lang.NoSuchMethodError`) rather than parsing one. – Andrii Abramov Feb 08 '19 at 13:41
  • Perhaps you're right. To me it looks like it can't find the method in the object or the apply method because your parsing isn't working. That's my guess to what is wrong. But maybe it's also because I had parsing issues in the past I seem to think that's the rootcause. Perhaps someone else will have a better answer. I'm really not sure, which is why I left a comment instead of an answer too :) – GamingFelix Feb 08 '19 at 13:45
  • 1
    I'd first try a full clean and rebuild, since macros are involved, and then I'd confirm that the runtime play-json version is 2.7.0 (at a glance the error looks consistent with building against 2.7.0 and then having e.g. 2.6 around at runtime). – Travis Brown Feb 08 '19 at 13:48
  • I've tried full clean and rebuild. Unfortunately this didn't help. Maybe this is some how related to Play 2.6.x? I am trying to use play-json 2.7.x with Play 2.6.x. `[info] java.lang.RuntimeException: java.lang.NoSuchMethodError: play.api.libs.json.JsonConfiguration$.apply$default$2()Lplay/api/libs/json/OptionHandlers; [info] at play.api.mvc.ActionBuilder$$anon$10.apply(Action.scala:424)` – Andrii Abramov Feb 08 '19 at 13:53

1 Answers1

4

As Travis Brown pointed out you have a version conflict.

As in the Play Project there is a play-json included, you should not have another dependency to play-json.

And if you have (as I have a multi-module project), make sure the the major version fits.

e.g. in plugins.sbt:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.0")

and as a dependency (not in the play module!):

"com.typesafe.play" %% "play-json" % "2.7.1"
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
pme
  • 14,156
  • 3
  • 52
  • 95
  • 1. _.X._ is not a major version. It is MINOR update. 2. It is horrible to break *binary* compatibility in MINOR update. – Andrii Abramov Apr 08 '19 at 14:53
  • it is a bit confusing, but `play-json` is a separate project with its own release cycle - for major updates they have the same. – pme Apr 09 '19 at 06:43