Skip to content

Instantly share code, notes, and snippets.

@jkyamog
Created September 11, 2013 10:37
Show Gist options
  • Save jkyamog/6521932 to your computer and use it in GitHub Desktop.
Save jkyamog/6521932 to your computer and use it in GitHub Desktop.
Play api json date reader and writer for extended mongo dates
object MeetingMongo {
val dateReader: Reads[Date] = new Reads[Date] {
def reads(jsValue: JsValue): JsResult[Date] = {
(jsValue \ "$date").validate[Long].map { l => new Date(l) }
}
}
val dateWriter: Writes[Date] = new Writes[Date] {
def writes(date: Date): JsValue = Json.obj("$date" -> JsNumber(date.getTime))
}
implicit val dateFormatter = Format(dateReader, dateWriter)
implicit val formatter = Json.format[Meeting]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment