This repository was archived by the owner on Feb 20, 2019. It is now read-only.
Running into problems when pickling Map and HashMap #63
Open
Description
steps (0.10.0)
scala-pickling> console
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.11.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.collection.immutable
import scala.collection.immutable
scala> import scala.pickling._, Defaults._, json._
import scala.pickling._
import Defaults._
import json._
scala> immutable.HashMap(( for (j <- 0 until 20) yield j -> "Test" ): _* ).pickle.value
problem (0.10.0)
scala> println(immutable.HashMap(( for (j <- 0 until 20) yield j -> "Test" ): _* ).pickle.value)
{
"$type": "scala.collection.immutable.HashMap.HashTrieMap",
"bitmap": 2044127639,
"elems": {
"elems": [
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
},
{
"$type": "scala.collection.immutable.HashMap"
}
]
},
"size0": 20
}
original report
My data structure is stored as a Map and when I try to pickle it I run into some weird issues.
When pickling a immutable.HashMap using the following example code.
import scala.collection.immutable
import scala.pickling._
import json._
object Test {
def main(args : Array[String]) {
println(immutable.HashMap(( for (j <- 0 until 20) yield j -> "Test" ): _* ).pickle.toString)
}
}
as output I get
JSONPickle({
"tpe": "scala.collection.immutable.HashMap.HashTrieMap",
"bitmap": 2044127639,
"elems": {
},
"size0": 20
})
If I use instead the following snippet of code
import scala.collection.Map
import scala.pickling._
import json._
object Test {
def main(args : Array[String]) {
println(Map(( for (j <- 0 until 20) yield j -> "Test" ): _* ).pickle.toString)
}
}
I also end up with
JSONPickle({
"tpe": "scala.collection.immutable.HashMap.HashTrieMap",
"bitmap": 2044127639,
"elems": {
},
"size0": 20
})
only when I don't explicitly import Map do I end up with the correct output.