Skip to content

Instantly share code, notes, and snippets.

@davidmweber
Created June 2, 2014 12:35
Show Gist options
  • Save davidmweber/e5a6e35cd919e50d0c77 to your computer and use it in GitHub Desktop.
Save davidmweber/e5a6e35cd919e50d0c77 to your computer and use it in GitHub Desktop.
Simple Scala pickler example
package pickleme
trait Zero
case class One(a:Int) extends Zero
case class Two(s:String) extends Zero
object Test extends App {
import scala.pickling._
import json._
// String that can be sent down a wire
val wire: String = Two("abc").pickle.value
// On the other side, just use a case class
wire.unpickle[Zero] match {
case One(s) => println(s)
case Two(a) => println(a)
case unknown => println(unknown.getClass.getCanonicalName)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment