Create a transforming pickler that takes an object of type A
and transforms it into B
, which is then pickled.
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 of the original object
Type for the object used for pickling
Function that takes B
and transforms it into A
Function that takes A
and transforms it into B