Take the 2-minute tour ×

I have an application that manages a graph of nodes and arcs, where the nodes have a small number of properties. Now I'm at the point where I need to save out the data, and I need to choose a serialization format. Here's a list of some of the obvious ones, but there may be others I haven't considered.

  • Java Serialization
  • XML
  • JSON
  • Yaml
  • Google protocol buffers

Java serialization is a non-starter for a number of reasons, even in the Java world XML and other serializations formats are preferred for the reasons of interoperability, schema migration, and ease of use.

Scala's XML support seems like an obvious choice. However, I personally find the idea of XML literals embedded in source code distasteful (even the creator of the language admits he regrets this decision). This feature perhaps makes more sense when generating marked-up text - but when serializing objects, you really want a higher level API which separates as much as possible the code that understands the internal data structures, from the code that understands the syntax of the serialization format - which means that ideally you should never actually see any XML in your source code. Also, a Google web search reveals a number of blog posts that claim that Scala's XML DOM has lots of warts and is awkward to use. (There are also a number of libraries that claim to improve the situation, but then it becomes a matter of choosing which one.)

JSON and Yaml would also work - the issue here is that the most popular serialization libraries are in Java, and so the task involves choosing or writing an appropriate Scala wrapper class. Also, many of these libraries rely on bean reflection, which is possible but somewhat awkward in Scala requiring additional annotations to get things to work.

Finally, I've used Google protobufs for a lot of other serialization tasks. The nice part is that the protoc compiler can generate elegant APIs that match the idioms of the target language. However, in this case one of the strengths of protobufs, which is the small size of the encoded data stream, isn't important, and I'd rather have something where the serialized data is human-readable.

share|improve this question

1 Answer 1

It seems to me that JSON is a popular choice in the Scala world, particularly the typeclass-based API provided by the Play framework: http://www.playframework.org/documentation/2.0.1/ScalaJson

share|improve this answer
So I'm a little confused about the scope of Play; I'd like to add minimal dependencies if possible, and not rely on some giant framework with tons of bells and whistles (especially given that this is a Swing app, not a web app.) Ideally I'd like to be able to just drop a .jar file into my Eclipse project and not have to deal with Maven or sbt or any of that. Some of the other libraries I've been looking at seem to require a lot of infrastructure in order to incorporate them into a project. –  Talin Jan 28 '13 at 7:42
hmm, somehow I was under the impression that Play was properly modularized, but it seems I was wrong –  user500592 Jan 28 '13 at 10:44
There is spray-json also github.com/spray/spray-json –  David Holbrook Jan 28 '13 at 18:38
Both Jerkson and spray-json looked really good, but I could not figure out how to incorporate them into my Eclipse project - the only jar files that I could find to download are Maven build artifacts, which apparently aren't normal jars. –  Talin Jan 29 '13 at 4:49

Your Answer


