Open amnaredo opened 3 years ago
I am facing the same error in my (closed-source) project with upickle v0.3.0.
However, creating a minimal test-case is a challenge. I tried the above code by @chandu0101 and it didn't fail, in a fresh project.
Original Author: hrj
Odd, this works for me in both 2.10.4 and 2.11.7 in the REPL:
scala> case class Result2(name : String,
| whatever : String,
| types : List[String]
| )
defined class Result2
scala>
scala> case class GeoCoding2(results : List[Result2], status: String)
defined class GeoCoding2
scala>
scala> read[GeoCoding2]("")
<console>:15: error: not found: value read
read[GeoCoding2]("")
^
scala> upickle.default.read[GeoCoding2]("")
upickle.Invalid$Json
at upickle.json.package$.read(package.scala:11)
at upickle.Types$class.read(Types.scala:133)
at upickle.default$.read(Api.scala:25)
... 43 elided
Original Author: lihaoyi
Ok, I figured it. If the classes (like GeoCoding and Result) are defined in another file, and UPickleNewVersionService is defined and used in a different file, I get the error.
Original Author: hrj
Here's a further minimalised test:
package test
case class C1(name : String, types : List[String])
case class C2(results : List[C1])
package test
import upickle.default._
object Test {
object Service {
def getSample() = {
read[C2]("")
}
}
//mytest case
def xyz(x:String) {
Service.getSample()
}
}
libraryDependencies += "com.lihaoyi" %% "upickle" % "0.3.0"
scalaVersion := "2.11.7"
[error] file2.scala:8: Couldn't derive type (List[test.C1],)
[error] read[C2]("")
Original Author: hrj
@lihaoyi it works in REPL but fail in the test. Just add the code
object OtherStuffs {
case class Result2(name : String, whatever : String, types : List[String])
case class GeoCoding2(results : List[Result2], status: String)
}
import OtherStuffs._
'complex {
read[GeoCoding2]("")
}
produces this:
uPickle does not know how to read [example.OtherSuffs.GeoCoding2]s; define an implicit Reader[example.OtherSuffs.GeoCoding2] to teach it how
[error] read[GeoCoding2]("")
[error] ^
[error] /Users/binh/codes/scalajs/upickle-pprint/upickle/shared/src/test/scala/example/ExampleTests.scala:84: uPickle does not know how to read [example.OtherSuffs.GeoCoding2]s; define an implicit Reader[example.OtherSuffs.GeoCoding2] to teach it how
[error] read[GeoCoding2]("")
[error] ^
Original Author: ngbinh
FYI...I hit this too but for a different reason. I had >21 params on my case class.
Original Author: bjenkinsgit
error :
/UPickleNewVersionService.scala:9: Couldn't derive type (List[Result2], String) [error] val g = read[GeoCoding2]("")
ID: 95 Original Author: chandu0101