Cannot Generate unpickler for case class with immutable HashMaps

497 views Asked by At

I've recently come across scala-pickling and I'm trying to see how I can use it in a project, so I've been working through a simple example of a case class with immutable hashmaps. In this example, scala-pickling doesn't generate an unpickler and I can't figure out why. The Following is a REPL session to demonstrate the issue:

scala> case class Foo(a: HashMap[Symbol,Symbol], b: HashMap[Symbol,Double], c: Symbol, d: Double)
defined class Foo

scala> val bar = Foo(new HashMap[Symbol,Symbol](), new HashMap[Symbol,Double](), 'A, 1.4)
bar: Foo = Foo(Map(),Map(),'A,1.4)

scala> val pickled = bar.pickle
pickled: scala.pickling.json.JSONPickle = 
JSONPickle({
  "tpe": "Foo",
  "c": {
    "name": "A"
  },
  "d": 1.4,
  "a": {

  },
  "b": {

  }
})

scala> val unpickled = pickled.unpickle[Foo]
<console>:18: error: Cannot generate an unpickler for Foo. Recompile with -Xlog-implicits for details
   val unpickled = pickled.unpickle[Foo]

can anybody point out what I'm doing wrong? or is there any issue with scala-pickling?

EDIT: Actually, the same seems to happen when I generate a class with one attribute which is just a Symbol (I'll post another REPL session). Is there a special way to deal with Symbols in scala-pickling?

scala> case class Foo(symb: Symbol)
defined class Foo

scala> val foo = Foo('A)
foo: Foo = Foo('A)

scala> val pick = foo.pickle
pick: scala.pickling.json.JSONPickle = 
JSONPickle({
  "tpe": "Foo",
  "symb": {
    "name": "A"
  }
})

scala> val unpick = pick.unpickle[Foo]
<console>:17: error: Cannot generate an unpickler for Foo. Recompile with -Xlog-implicits for details
   val unpick = pick.unpickle[Foo]
1

There are 1 answers

0
Trev On

I know this is an old post, but try

import scala.pickling._, Defaults._, json._