Are there are any examples, tutorials or docs for serialization / pickling / marshalling objects in Scala? I know of existence of scala.util.Marshal and scala.reflect.internal.pickling, but what is a difference between them? how can I use it? Is that some experimetal feature or can I use it in production ... ?
Asked
Active
Viewed 1,660 times
1
-
`scala.util.Marshal` is deprecated. Generally, just use the platform capabilities for (de)serialization, works without problems. – soc May 20 '12 at 11:50
2 Answers
1
You should use either java serialization (I recommend using the Externalizable approach for complex cases). You can find lots of tutorials by googling "java serialization tutorial".
If you want to stay in Scala, you should have a look to SBinary which uses composable type classes. The project seems old and unmaintained but works like a charm with Scala 2.9.2. There's a tutorial link in the README and I'm currently writing another one.

paradigmatic
- 40,153
- 18
- 88
- 147
-
-
The only difference is that in Scala serializable is an annotation. Have a look at this question: http://stackoverflow.com/questions/3442171/how-do-i-use-a-serializable-scala-object – paradigmatic May 20 '12 at 19:54
-
Just note, Java Serialization does not handle immutable List[A] using generics. You'll have to use Array[A] instead. I'm not sure about other containers. Externalize may not be the way to go in the case of case classes (pardon the pun) Externalize requires a no-arg constructor with mutator fields in order for it to work. This may not be ideal for those who are trying to stick to Scala's general convention to stick with immutable objects. – Daniel Macias Jun 02 '13 at 06:29
1
Not sure about the requirements you have, but it's worth looking at Google's Protocol Buffers and Apache Thrift. Both provide efficient mechanism for serialization.
There is a Protocol Buffers scala compiler ScalaBuff

Nabegh
- 3,249
- 6
- 25
- 26
-
Wow! Awesome seeing my project being mentioned as a possible solution! :) I should add that I'm still working on some of the more advanced parts, and it may not be as easy to set up as it should be (I have to make a simple example project), but it should still work pretty well (the protobuf protocol is awesome!). If anyone has any questions, just open an issue on the GitHub page and I'll respond as soon as possible! For an example of usage (with Android), look up my [SenseGrid project](https://github.com/SandroGrzicic/sensegrid). – Sandro Gržičić Jan 25 '13 at 21:13