Getting started

Add following dependency declaration to your Scala project

"io.suzaku" %% "boopickle" % "1.3.0"

On a Scala.js project the dependency looks like this

"io.suzaku" %%% "boopickle" % "1.3.0"

To use it in your code, simply import the Default object contents. All examples in this document assume this import is present.

import boopickle.Default._

To serialize (pickle) something, just call Pickle.intoBytes with your data. This will produce a binary ByteBuffer containing an encoded version of your data.

val data = Seq("Hello", "World!")
val buf = Pickle.intoBytes(data)

And to deserialize (unpickle) the buffer, call Unpickle.fromBytes, specifying the type of your data. BooPickle doesn't encode any type information, so you must use the same types when pickling and unpickling.

val helloWorld = Unpickle[Seq[String]].fromBytes(buf)

Supported types

BooPickle has built-in support for most of the regular Scala types, including

  • primitives: Boolean, Byte, Short, Char, Int, Long, Float, Double and String
  • common types: Tuples, Option, Either, Duration, UUID, BigInt, BigDecimal and ByteBuffer
  • collections, both mutable and immutable, including: Array, Vector, List, Sets, Maps and any Iterable with a CanBuildFrom implementation
  • case classes and case objects (via a macro)
  • traits as a base for a class hierarchy

results matching ""

    No results matching ""