14

I'm interested in canvasing opinion about options for Scala data-structure serialization. I'd like to find something which is developed enough to allow (if possible) efficient binary serialization of the Scala collection types (i.e. not using generic Java reflection - I don't want to be serializing all parts of a collection class, including internal book-keeping data) but also allows me to extend functionality for my own purposes/classes: I am more than happy to have to write serialization code for each of our own classes, but would rather not have to do it for collections from the Scala standard libraries. In C++ I get a lot of this functionality from the Boost serialization library.

I've used SBinary in the past and it does some of what I want, but is not getting obvious active maintenance and doesn't seem (afaik) to keep track of objects already serialized (e.g. for DAGs or cyclic datastructures).

Are there other Scala-specific solutions, or if not, what are your recommendations for efficient binary serialization?

Alex Wilson
  • 6,690
  • 27
  • 44
  • Binary serialization is, generally, a hard problem. Since the Scala community is on the smaller side, I suspect many people just live with a Java library (see http://stackoverflow.com/questions/239280/which-is-the-best-alternative-for-java-serialization) or roll their own. – Donald.McLean Sep 20 '12 at 14:25

2 Answers2

2

Probably, if you only need to serialize data and not whole java objects, best solutions are :

I am using msgpack and bson in several projects and they work pretty well. I really recommend msgpack – has most efficient binary representation (of these three) and is fully JSON compatibile.

spinus
  • 5,497
  • 2
  • 20
  • 26
1

A protocol buffers compiler for Scala: https://github.com/SandroGrzicic/ScalaBuff - perhaps this can help?

There's a couple of other links at the bottom of this page: http://doc.akka.io/docs/akka/snapshot/scala/serialization.html

bcolyn
  • 71
  • 2
  • Thanks for the suggestion. I'm keen to keep it all in one language if possible though. I'm currently using SBinary again, but it feels like with a bit more love it could be much more useful. I guess I should put my money where my mouth is and fork it... :-) – Alex Wilson Oct 10 '12 at 13:17