Open amnaredo opened 3 years ago
I can reproduce a similar issue with the following code using Autowire and uPickle in Play:
import upickle.default._
import upickle.Js
object AutowireServer extends autowire.Server[Js.Value, Reader, Writer] {
override def write[R: Writer](r: R) = writeJs(r)
override def read[R: Reader](s: Js.Value) = readJs[R](s)
}
class Application extends Controller {
def autowireApi(path: String) = Action.async(parse.tolerantText) {
implicit request =>
AutowireServer.route[Api](serverApi) {
autowire.Core.Request(path.split("/"), json.read(request.body).asInstanceOf[Js.Obj].value.toMap)
}
.map(s => Ok(json.write(s)))
}
}
server/app/controllers/Application.scala:47: diverging implicit expansion for type upickle.default.Writer[T1]
[error] starting with macro method macroW in trait LowPriX
[error] AutowireServer.route[Api](serverApi) {
[error] ^
[error] one error found
[error] (server/compile:compileIncremental) Compilation failed
I am using uPickle 0.4.1, Scala 2.11.7 and Play 2.4.6
Original Author: damienfir
@damienfir @onlyNexusHere Have either of you found workarounds? I'm experiencing the same problem, and it's a major blocker.
Original Author: danielyli
Yes I found a workaround. I was trying to use uPickle on a case class
extending a trait
and it gave me the error. Replacing the trait
by a sealed trait
solved the problem.
Original Author: damienfir
Thanks for letting me know. Unfortunately, I'm already using sealed
everywhere, so that isn't the problem. I'll keep hunting...
Original Author: danielyli
@danielyli : Did you find a workaround?
Original Author: 192709
I am hitting this error as well.
Original Author: ebruchez
@192709 No, I ended up using another library.
Original Author: danielyli
@danielyli: Thank you for your reply. I read http://www.gitterforum.com/discussion/lihaoyi-upickle-pprint?page=23 and could bring it to work.
Original Author: 192709
Hi,
had the same issue.
def autowireAjax(path: String) = Action.async[String](parse.text) { request => val e: String = request.body val f: Future[String] = AutoWireServer.route[SharedApi](this)(autowire.Core.Request( path.split('/'), upickle.json.read(e).asInstanceOf[Js.Obj].value.toMap) ).map(upickle.json.write(_,2)) val fr: Future[Result] = f.map { s => Ok(s) } fr }
I tried to change to this
def autowireAjax(path: String) = Action.async[String](parse.tolerantText) { request => val e: String = request.body val f: Future[String] = AutoWireServer.route[SharedApi](this)(autowire.Core.Request( path.split('/'), upickle.json.read(e).asInstanceOf[Js.Obj].value.toMap) ).map(upickle.json.write(_,2)) val fr: Future[Result] = f.map { s => Ok(s) } fr }
and this worked.
Original Author: ASchmidt84
What is the progress on this? Original Author: strelec
If you want me to have time to look at this, chip in https://www.patreon.com/lihaoyi Original Author: lihaoyi
This happened to me when I changed a sealed trait
to a sealed class
, call it X
. If I try to serialize a case class with a field X
, I get the implicits error. If I try to serialize an instance of X
, I get a "Couldn't derive type X" error. This unfortunately didn't help (though it might help someone else). I worked around it by keeping it as a trait and using an abstract method instead of a field.
Original Author: bmccutchon
Bug bankruptcy Original Author: lihaoyi
uPickle unable to parse through this code:
With exactly this code, I get this error message:
With the
def writeKClos
anddef readKClos
uncommented and the last two lines commented, I get:When
def writeState
anddef readState
are not commented and all following lines are commented, the code compiles fine.I am not sure what diverging implicit expansion means in terms of how my project is laid out. However, everything that is included in the file should compile file. It does not, and I have no idea why.
Notes: This is all done with sbt on a Mac. Nothing in the project is imported, and no other file uses this file. This is not quite what I was using in the project, but this is the simplest example where the behavior shows.
ID: 159 Original Author: onlyNexusHere