Last active
December 12, 2015 04:49
-
-
Save stephanos/4717443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.api.libs.json.Json | |
case class MyClass(id: Int, text: String) | |
object MyClass { | |
implicit val mailRead = Json.reads[MyClass] | |
def apply(id: Int) = | |
apply(id, "") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[error] exception during macro expansion: | |
[error] scala.ScalaReflectionException: value apply encapsulates multiple overloaded alternatives and cannot be treated as a method. Consider invoking `<offending symbol>.asTerm.alternatives` and manually picking the required method | |
[error] at scala.reflect.api.Symbols$SymbolApi$class.asMethod(Symbols.scala:279) | |
[error] at scala.reflect.internal.Symbols$SymbolContextApiImpl.asMethod(Symbols.scala:73) | |
[error] at play.api.libs.json.JsMacroImpl$.readsImpl(JsMacroImpl.scala:44) | |
[error] one error found |
Thank you for the answer! By the way, the JSON API rulez!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
You should have a mix of 2 issues here apparently if you use Play2.1-RC2
1st one
First if you want to put your implicit macro in companion, you should write it like
It's explained in this ticket https://play.lighthouseapp.com/projects/82401/tickets/932-new-json-api-and-companion-objects
This issue has been corrected in Play2.1-master (but won't be in 2.1.0 final)
2nd one
You shouldn't override apply function in companion object because Scala macro can't decide which one it should choose.
There is not workaround for this one but to call your function with another name that apply like