question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Json macros breakage, cant find matching apply/unapply

See original GitHub issue

Im getting some macro breakage in what looks like a situation that should work.

This is with 2.2.0_M2 of play-json.

PlayJsonBoilerplate.scala:39: No apply function found matching unapply return types
[error]     Json.reads[Collaborator]
[error]               ^

But, this code works fine, and is in scope for the above ^

implicit lazy val ReadsCollaboratorCollaboratedUser: Reads[Collaborator.CollaboratedUser] = {
    import com.heroku.platform.api.Collaborator.CollaboratedUser
    Json.reads[Collaborator.CollaboratedUser]
  }

Apply and Unapply line up afaik?

scala> import com.heroku.platform.api._
import com.heroku.platform.api._

scala> Collaborator.apply _
res0: (String, String, com.heroku.platform.api.Collaborator.CollaboratedUser) => com.heroku.platform.api.Collaborator = <function3>

scala> Collaborator.unapply _
res1: com.heroku.platform.api.Collaborator => Option[(String, String, com.heroku.platform.api.Collaborator.CollaboratedUser)] = <function1>

Must be to do with the nested case class in the companion?

object Collaborator {
  case class CollaboratedUser(email: String, id: String)
}

case class Collaborator(created_at: String, id: String, user: CollaboratedUser)

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
cridmanncommented, Nov 17, 2014

I ran into a similar issue when having an enumeration defined in its companion class. I fixed this by being very explicit about the type within the case class definition.

Try seeing if this works:

case class Parent( id: String, child: Parent.Related.Child) { }

0reactions
cchantepcommented, Aug 27, 2016

More recent duplicate #3244

Read more comments on GitHub >

github_iconTop Results From Across the Web

Play JSON serialize/deserialize - scala - Stack Overflow
Play JSON serialize/deserialize ... Your code seems to compiles fine. Have you added other apply or unapply methods in Work object? – Cyrille ......
Read more >
circe/circe - Gitter
Good morning! Are there any special specs2 matchers for circe.Json , which may take ignore order of object fields or presence/absence of null-valued...
Read more >
Scala pattern matching: apply the unapply - Medium
apply (...) . We are using it to construct new instances of FullName without needing the new keyword. unapply does the opposite —...
Read more >
[Solved]-Pattern match Jackson JSON in Scala-scala
case class DomainObjectA(v1: String, v2: String) object DomainObjectAExtractor { def unapply(m: Map[String, String]) = for { v1 <- m.get("key1") v2 ...
Read more >
serialization in sbt - Google Groups
(I'm not actually sure play-json would break as long as we have apply and unapply, I think it reflects those and uses them...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found