TransformPicklers
trait TransformPicklers
Value members
Concrete methods
def transformPickler[A, B](transformFrom: B => A)(transformTo: A => B)(implicit p: Pickler[B]): Pickler[A]
Create a transforming pickler that takes an object of type A
and transforms it into B
, which is then pickled.
Similarly a B
is unpickled and then transformed back into A
.
Create a transforming pickler that takes an object of type A
and transforms it into B
, which is then pickled.
Similarly a B
is unpickled and then transformed back into A
.
This allows for easy creation of picklers for (relatively) simple classes. For example
// transform Date into Long and back
implicit val datePickler = transformPickler((t: Long) => new java.util.Date(t))(_.getTime)
Note that parameters are in reversed order.
- Type Params
- A
Type of the original object
- B
Type for the object used for pickling
- Value Params
- transformFrom
Function that takes
B
and transforms it intoA
- transformTo
Function that takes
A
and transforms it intoB