Open julienrf opened 10 years ago
If I trade the implicit parameters for implicit vals, the above code does not compile anymore:
trait ModuleUsage extends Module {
import scala.pickling._
implicit def p: SPickler[User]
implicit def t: FastTypeTag[User]
def pickle(u: User): Unit = {
import binary._
println(u.pickle)
}
}
object ModuleUsageImpl extends ModuleUsage with App {
case class User(name: String) extends UserLike
import scala.pickling._
import scala.pickling.binary._
implicit val p = implicitly[SPickler[User]]
implicit val t = implicitly[FastTypeTag[User]]
pickle(User("Heather"))
}
I get the following error:
[info] pickling.this.SPickler.genPickler is not a valid implicit value for scala.pickling.SPickler[ModuleUsageImpl.User] because:
[info] stepping aside: repeating itself
[info] implicit val p = implicitly[SPickler[User]]
[info] ^
Consider the following trait:
I’d like to write a function that pickles a value of type
User
, which is abstract. Here is what I came out with:This trait can then be used as follows:
My problem is that I’d like to avoid the imports to at the
ModuleUsageImpl
site, especially thescala.pickling.binary._
import. By the way, if I importscala.pickling.json._
at this place, the pickling format is still binary (which is the one that is imported in thepickle
function). Maybe mypickle
function is not taking the right implicit parameters?