json - Scala Pickling for sql.Timestamp -
i using scala pickling library(0.9.0-snapshot) json serializing.
i write custom pickler , unpickler serializing , deserializing sql.timestamp fields normal fields, able serialize time stamp field overriding pickle method in spickler, want desrialize timestamp value in json string( string value) timestamp field. possible?
i mean,
case class t1(id: long, name: string, time: timestamp)
to json
{ "tpe" : "t1", "id" : "42", "name": "name", "time": "2014-10-17 17:19:29.97" }
is possible, unable unpickle 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 this.
class timestamppickler(implicit val format: pickleformat) extends spickler[timestamp] 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
json scala serialization scala-pickling
No comments:
Post a Comment