com.quantarray.anaheim.spray.json.LocalDateTimeFormatting.scala Maven / Gradle / Ivy
package com.quantarray.anaheim.spray.json
import spray.json.{DeserializationException, JsString, JsValue, RootJsonFormat}
import java.time.LocalDateTime
trait LocalDateTimeFormatting {
implicit object LocalDateTimeFormat extends RootJsonFormat[LocalDateTime] {
override def write(ld: LocalDateTime): JsString = JsString(ld.toString)
override def read(json: JsValue): LocalDateTime = json match {
case JsString(s) => LocalDateTime.parse(s)
case _ => throw DeserializationException(s"Cannot parse $json.")
}
}
}