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

Following example doesn't work #27

Closed
mikkelspring opened this issue Feb 24, 2016 · 5 comments
Closed

Following example doesn't work #27

mikkelspring opened this issue Feb 24, 2016 · 5 comments

Comments

@mikkelspring
Copy link

Hello, I'm fairly sure I'm using this library correctly, but for some reason the macro is outputting an empty read and write. I first noticed this on my own use case, but it is also replicating with the basic example from the readme.

sealed trait Foo
case class Bar(x: Int) extends Foo
case class Baz(s: String) extends Foo
case class Bah(s: String) extends Foo
implicit val format = Variants.format[Foo]

Leads to

play.api.libs.json.Format[Foo](play.api.libs.json.Reads[Foo](((json) => Impl.this.defaultDiscriminator.reads(json).flatMap( match {

}))), play.api.libs.json.Writes[Foo]( match {

}))
Apply(TypeApply(Select(Select(Select(Select(Ident(TermName("play")), TermName("api")), TermName("libs")), TermName("json")), TermName("Format")), List(Ident(models.Propagate.Foo))), List(Apply(TypeApply(Select(Select(Select(Select(Ident(TermName("play")), TermName("api")), TermName("libs")), TermName("json")), TermName("Reads")), List(Ident(models.Propagate.Foo))), List(Function(List(ValDef(Modifiers(PARAM), TermName("json"), TypeTree(), EmptyTree)), Apply(Select(Apply(Select(Select(This(TypeName("Impl")), TermName("defaultDiscriminator")), TermName("reads")), List(Ident(TermName("json")))), TermName("flatMap")), List(Match(EmptyTree, List())))))), Apply(TypeApply(Select(Select(Select(Select(Ident(TermName("play")), TermName("api")), TermName("libs")), TermName("json")), TermName("Writes")), List(Ident(models.Propagate.Foo))), List(Match(EmptyTree, List())))))

Do you have any ideas about what could be causing this? Thanks!

@mikkelspring
Copy link
Author

Sorry, I didn't notice this was from the 2.0 branch.

Now that I've updated to 3.0 I have

sealed trait Foo
case class Bar(s: String, i: Int) extends Foo
case object Baz extends Foo

object Foo {
  implicit val format = oformat[Foo]
}

Error:(35, 32) could not find implicit value for parameter derivedReads: shapeless.Lazy[julienrf.json.derived.DerivedReads[models.Foo]]
implicit val format = oformat[Foo]
^
Error:(35, 32) not enough arguments for method oformat: (implicit derivedReads: shapeless.Lazy[julienrf.json.derived.DerivedReads[models.Foo]], implicit derivedOWrites: shapeless.Lazy[julienrf.json.derived.DerivedOWrites[models.Foo]])play.api.libs.json.OFormat[models.Foo].
Unspecified value parameters derivedReads, derivedOWrites.
implicit val format = oformat[Foo]

                           ^

@mikkelspring
Copy link
Author

OK I copied and pasted directly from the test and it worked. For some reason I don't understand, it is required to explicitly specific the OFormat type like so

implicit val format: OFormat[Foo] = oformat[Foo]

Could be added to the docs? Thanks for your work.

@mikkelspring mikkelspring changed the title Empty macro generation in Play 2.4 Following example doesn't work Feb 24, 2016
@janakagamini
Copy link

I have the same exact error (could not find implicit value for parameter... and not enough arguments...), and I cant get rid of it

Here's what my code looks like:

object Foo {
  implicit val format: OFormat[Foo] = derived.oformat[Foo]
}

sealed trait Foo

//object Bar {
//  implicit val format: OFormat[Bar] = derived.oformat[Bar]
//}

case class Bar(s: String) extends Foo

//object Zoo {
//  implicit val format: OFormat[Zoo] = derived.oformat[Zoo]
//}

case class Zoo(i: Int) extends Foo

I get the same result if I un-comment the commented parts as well.

What am I missing?

@julienrf
Copy link
Owner

It will work if you move the Foo object definition after the case classes.

I’m sorry about that but it seems to be one of the issues of knownDirectSubclasses: https://groups.google.com/d/topic/scala-internals/LRfKffsPxVA/discussion

@janakagamini
Copy link

Yes just realized it after I read through the documentation for v2.0.

Now I can compile but I still cant get it to de-serialize a websocket frame (Play 2.5), but that is probably a totally different issue.

Thank you for responding @julienrf

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

3 participants