scala - Custom JodaTime serializer using Play Framework's JSON library? -
how implement custom jodatime's datetime serializer/deserializer json? i'm inclined use play framework's json library (2.1.1). there default datetime serializer, uses dt.getmillis
instead of .tostring
return iso compliant string.
writing reads[t] amd writes[t] case classes seems straightforward, can't figure out how same datetime.
i use play 2.3.7 , define in companion object implicit reads/writes string pattern:
case class user(username:string, birthday:org.joda.time.datetime) object user { implicit val yourjodadatereads = reads.jodadatereads("yyyy-mm-dd't'hh:mm:ss'z'") implicit val yourjodadatewrites = writes.jodadatewrites("yyyy-mm-dd't'hh:mm:ss'z'") implicit val userformat = json.format[user] }
Comments
Post a Comment