Last active
December 4, 2019 20:47
-
-
Save jeroenr/4fd9b4f9be24c3c549d16e5886f80527 to your computer and use it in GitHub Desktop.
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
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