pickling icon indicating copy to clipboard operation
pickling copied to clipboard

Compiler error when trying to unpickle `akka.actor.Address`

Open hseeberger opened this issue 10 years ago • 1 comments

scala> val address = Address("akka", "some-system")
address: akka.actor.Address = akka://some-system

scala> import scala.pickling.Defaults._
import scala.pickling.Defaults._

scala> import scala.pickling.binary._
import scala.pickling.binary._

scala> val bytes = address.pickle.value
bytes: Array[Byte] = Array(0, 0, 0, 18, 97, 107, 107, 97, 46, 97, 99, 116, 111, 114, 46, 65, 100, 100, 114, 101, 115, 115, 0, 0, 0, 4, 97, 107, 107, 97, 0, 0, 0, 11, 115, 111, 109, 101, 45, 115, 121, 115, 116, 101, 109, 0, 0, 0, 15, 115, 99, 97, 108, 97, 46, 78, 111, 110, 101, 46, 116, 121, 112, 101, 0, 0, 0, 15, 115, 99, 97, 108, 97, 46, 78, 111, 110, 101, 46, 116, 121, 112, 101)

scala> BinaryPickle(bytes).unpickle[Address]
<console>:55: error: an expression of type Null is ineligible for implicit conversion
              BinaryPickle(bytes).unpickle[Address]
                                          ^

hseeberger avatar Feb 19 '15 17:02 hseeberger

Maybe because of the private constructor?

scala> :pa
// Entering paste mode (ctrl-D to finish)

case class Foo private (bar: String)
object Foo { def apply(): Foo = new Foo("bar") }

// Exiting paste mode, now interpreting.

defined class Foo
defined object Foo

scala> val foo = Foo()
foo: Foo = Foo(bar)

scala> val bytes = foo.pickle.value
bytes: Array[Byte] = Array(0, 0, 0, -111, 36, 108, 105, 110, 101, 49, 48, 46, 36, 114, 101, 97, 100, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 36, 105, 119, 46, 70, 111, 111, 0, 0, 0, 3, 98, 97, 114)

scala> BinaryPickle(bytes).unpickle[Foo]
<console>:59: error: Cannot generate an unpickler for Foo. Recompile with -Xlog-implicits for details
              BinaryPickle(bytes).unpickle[Foo]
                                          ^

hseeberger avatar Feb 19 '15 17:02 hseeberger