I was trying to get into the new Scala Pickling library that was presented at the ScalaDays 2013: Scala Pickling
What I am really missing are some simple examples how the library is used.
I understood that I can pickle some object an unpickle it again like that:
import scala.pickling._
val pckl = List(1, 2, 3, 4).pickle
val lst = pckl.unpickle[List[Int]]
In this example, pckl is of the type Pickle. What exactly is the use of this type and how can I get for example get an Array[Byte] of it?
If you want wanted to pickle into bytes, then the code will look like this:
If you wanted json, the code would look almost the exact same with a minor change of imports:
How the object is pickled depends on the import type that you chose under
scala.pickling
(being eitherbinary
orjson
). Importbinary
and thevalue
property is anArray[Byte]
. Importjson
and it's a jsonString
.