Skip to content
This repository

Fast, customizable, boilerplate-free pickling support for Scala

Merge pull request #133 from phaller/topic/build-scala-version

Make Scala version used for build configurable via system property
latest commit b817f5bce0
Heather Miller heathermiller authored
README.md

scala/pickling

Build Status

Scala Pickling is an automatic serialization framework made for Scala. It's fast, boilerplate-free, and allows users to easily swap in/out different serialization formats (such as binary, or JSON), or even to provide your own custom serialization format.

Basic usage:

import scala.pickling._
import json._

val pckl = List(1, 2, 3, 4).pickle
val lst = pckl.unpickle[List[Int]]

For more, flip through, or watch the ScalaDays 2013 presentation!
For deeper technical details, we've also written an OOPSLA 2013 paper on scala/pickling, Instant Pickles: Generating Object-Oriented Pickler Combinators for Fast and Extensible Serialization.

Current version: 0.8.0, though Scala/pickling is in the early development stages, and any user feedback is highly appreciated!
Upcoming release: 0.9.0.

Quick Start

  • make sure scala-pickling.jar is on your classpath
  • use Scala 2.10.4

Get Scala Pickling

Scala Pickling for Scala 2.10.4 is available on Sonatype! You can find Scala Pickling under groupID: org.scala-lang and artifactID: scala-pickling_2.10. The current version is 0.8.0.

You can use Scala Pickling in your SBT project by simply adding the following dependency to your build file:

libraryDependencies += "org.scala-lang" %% "scala-pickling" % "0.8.0"

If you would like to run the latest development version of scala/pickling (0.9.0-SNAPHSHOT), you also need to add the Sonatype "snapshots" repository resolver to your build file:

libraryDependencies += "org.scala-lang" %% "scala-pickling" % "0.9.0-SNAPSHOT"

resolvers += Resolver.sonatypeRepo("snapshots")

For a more illustrative example, see a sample SBT project which uses Scala Pickling.

Or you can just directly download the jar.

What makes it different?

Scala Pickling...

  • can be Language-Neutral if you want it to be. Changing the format of your serialized data is as easy as importing the correct implicit pickle format into scope. Out of the box, we currently support a fast Scala binary format, as well as JSON. Support is currently planned for other formats. Or, you can even roll your own custom pickle format!
  • is Automatic. That is, without any boilerplate at all, one can instruct the framework to figure out how to serialize an arbitrary class instance. No need to register classes, no need to implement any methods.
  • Allows For Unanticipated Evolution. That means that you don’t have to extend some marker trait in order to serialize a given Scala class. Just import the scala.pickling package and call pickle on the instance that you would like to serialize.
  • gives you more Typesafety. No more errors from serialization/deserialization propagating to arbitrary points in your program. Unlike Java Serialization, errors either manifest themselves as compile-time errors, or runtime errors only at the point of unpickling.
  • has Robust Support For Object-Orientation. While Scala Pickling is based on the elegant notion of pickler combinators from functional programming, it goes on to extend the traditional form of pickler combinators to be able to handle open class hierarchies. That means that if you pickle an instance of a subclass, and then try to unpickle as a superclass, you will still get back an instance of the original subclass.
  • Happens At Compile-Time. That means that it’s super-performant because serialization-related code is typically generated at compile-time and inlined where it is needed in your code. Scala Pickling is essentially fully-static, reflection is only used as a fallback when static (compile-time) generation fails.
Something went wrong with that request. Please try again.