Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

Unpickle without specifying type #450

Open
DonDebonair opened this issue Mar 9, 2017 · 1 comment
Open

Unpickle without specifying type #450

DonDebonair opened this issue Mar 9, 2017 · 1 comment

Comments

@DonDebonair
Copy link

Is it possible to unpickle a pickled object without specifying the type?

Example:

import scala.pickling.Defaults._
import scala.pickling.binary._

object TestPickling extends App {

  case class Person(name: String, age: Int)

  val obj = Person("John", 65)
  
  val b = obj.pickle.value

  val objAgain = b.unpickle

}

The example doesn't work:

error: ambiguous implicit values:
 both value datePickler in trait DatePicklers of type => scala.pickling.Pickler[java.util.Date] with scala.pickling.Unpickler[java.util.Date]
 and value javaBigDecimalPickler in trait JavaBigDecimalPicklers of type => scala.pickling.Pickler[java.math.BigDecimal] with scala.pickling.Unpickler[java.math.BigDecimal]
 match expected type scala.pickling.Unpickler[T]
       b.unpickle

Am I missing something, or is this just not possible?

Usecase: serializing a set of objects of which the types are not known at compile time

@jcrowley66
Copy link

In your last line try: val objAgain = b.unpickle[AnyRef]

May also work with Any, but have not tried.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants