Skip to content

Instantly share code, notes, and snippets.

@jeroenr
Last active December 4, 2019 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroenr/4fd9b4f9be24c3c549d16e5886f80527 to your computer and use it in GitHub Desktop.
Save jeroenr/4fd9b4f9be24c3c549d16e5886f80527 to your computer and use it in GitHub Desktop.
package com.github.jeroenr.rain.radar
import java.time.Instant
import spray.json._
trait InstantJsonSupport extends DefaultJsonProtocol {
implicit object InstantFormat extends JsonFormat[Instant] {
def write(instant: Instant) = JsNumber(instant.toEpochMilli)
def read(json: JsValue): Instant = json match {
case JsNumber(value) ⇒ Instant.ofEpochMilli(value.toLong)
case other ⇒ deserializationError(s"Expected Instant as JsNumber, but got: $other")
}
}
}
object PrecipitationDataJsonSupport extends DefaultJsonProtocol with InstantJsonSupport {
implicit val locationFormat = jsonFormat3(Location.apply)
implicit val precipitationDataFormat = jsonFormat3(PrecipitationData.apply)
implicit val rainFormat = jsonFormat3(Rain.apply)
implicit val clutterFormat = jsonFormat2(Clutter.apply)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment