I'm trying to get a basic upickle example to work and it seems I'm missing something here. I want to try out the example provided on the readme page for upickle
import upickle._
sealed trait A
@key("Bee") case class B(i: Int) extends A
case object C extends A
Then, my code is:
object Model {
def main(args: Array[String]): Unit = {
val a = B(5): A
println(a)
val out = write(a)
println(out)
val a2 = read[A](out)
println(a2)
println(a == a2)
}
}
All I get is the error:
The referenced trait [[A]] does not have any sub-classes. This may happen due to a limitation of scalac (SI-7046) given that the trait is not in the same package. If this is the case, the hierarchy may be defined using integer constants.
I have two questions:
- How can I convince uPickle that the trait is in the same package? (Because it is.)
- Or if I can't: how can I define the hierarchy with integer constants?