havocp / pickling

Fast, customizable, boilerplate-free pickling support for Scala

Home Page:lampwww.epfl.ch/~hmiller/pickling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

scala/pickling

Build Status Stories in Ready

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 their 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 release: 0.9.0, though Scala/pickling is in the early development stages, and any user feedback is highly appreciated!
Upcoming releases: 0.9.1 and 0.10.0.

Quick Start

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

Get Scala Pickling

Scala Pickling is available on Sonatype for Scala 2.10 and Scala 2.11! You can find Scala Pickling under groupId: org.scala-lang and artifactId: scala-pickling_2.10 and scala-pickling_2.11. The current version is 0.9.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.9.0"

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

libraryDependencies += "org.scala-lang" %% "scala-pickling" % "0.9.1-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 (Scala 2.10, Scala 2.11).

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.

About

Fast, customizable, boilerplate-free pickling support for Scala

lampwww.epfl.ch/~hmiller/pickling