Is there a simple, hassle-free approach to serialization in Scala/Java that\'s similar to Python\'s pickle? Pickle is a dead-simple solution that\'s reasonably efficient in spa
Another good option is the recent (2016) **netvl/picopickle**:
- Small and almost dependency-less (the core library depends only on shapeless).
- Extensibility: you can define your own serializators for your types and you can create custom backends, that is, you can use the same library for the different serialization formats (collections, JSON, BSON, etc.); other parts of the serialization behavior like nulls handling can also be customized.
- Flexibility and convenience: the default serialization format is fine for most uses, but it can be customized almost arbitrarily with support from a convenient converters DSL.
- Static serialization without reflection: shapeless Generic macros are used to provide serializers for arbitrary types, which means that no reflection is used.
For example:
Jawn-based pickler also provides additional functions,
readString()
/writeString()
andreadAst()
/writeAst()
, which [de]serialize objects to strings and JSON AST to strings, respectively:
import io.github.netvl.picopickle.backends.jawn.JsonPickler._
case class A(x: Int, y: String)
writeString(A(10, "hi")) shouldEqual """{"x":10,"y":"hi"}"""
readString[A]("""{"x":10,"y":"hi"}""") shouldEqual A(10, "hi")