I am using scala pickling library(0.9.0-snapshot) for Json serializing.
I would like to write a custom pickler and unpickler for serializing and deserializing sql.Timestamp fields as normal fields, I am able to serialize the time stamp field by overriding the pickle method in Spickler, I also want to desrialize a timestamp value in json string( string value) to timestamp field. Is it possible?
I mean,
case class T1(id: Long, name: String, time: Timestamp)
to json as
{
"tpe" : "T1",
"id" : "42",
"name": "Name",
"time": "2014-10-17 17:19:29.97"
}
is possible, but unable to unpickle back to case class as
T1(42, "Name", new Timestamp(new Date().getTime)).pickle.value.unpickle[T1]
// Shows error scala.MatchError: 2014-10-17 17:19:29.97 (of class java.lang.String)
My current Implementation looks like this.
class TimestampPickler(implicit val format: PickleFormat) extends SPickler[Timestamp] with Unpickler[Timestamp] {
private val stringUnpickler = implicitly[Unpickler[String]]
override def pickle(picklee: Timestamp, builder: PBuilder): Unit = {
builder.hintTag(FastTypeTag.String).beginEntry(picklee.toString).endEntry()
}
override def unpickle(tag: => FastTypeTag[_], reader: PReader): Timestamp = {
// ToDo
}
}
implicit def genTimestampPickler(implicit format: PickleFormat) = new TimestampPickler