All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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.")
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy