Created
September 11, 2013 10:37
-
-
Save jkyamog/6521932 to your computer and use it in GitHub Desktop.
Play api json date reader and writer for extended mongo dates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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