blob: eb6da0b5994f058b0766586e44d2797f2fd68e61 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package triad
import java.time.Instant
import spray.json.{
DefaultJsonProtocol,
JsNumber,
JsValue,
JsonFormat,
RootJsonFormat
}
object ApiProtocol extends DefaultJsonProtocol {
implicit val timestampFormat: JsonFormat[Instant] = new JsonFormat[Instant] {
def read(js: JsValue) = Instant.ofEpochMilli(js.convertTo[Long])
def write(i: Instant) = JsNumber(i.toEpochMilli)
}
implicit val messageFormat: RootJsonFormat[Message] = jsonFormat(
Message.apply _,
"content",
"author",
"timestamp"
)
}
|