Converting DateTime to a JSON string
You have several problems here.
First, the toString() method in AbstractDateTime requires one or several arguments see here.
But I would advise you against this path and recommend using properly Spray-Json.
Spray-json does not know how to serialize Option[DateTime]
, therefore you have to provide a RootJsonFormat
for it.
This is what I am doing.
implicit object DateJsonFormat extends RootJsonFormat[DateTime] { private val parserISO : DateTimeFormatter = ISODateTimeFormat.dateTimeNoMillis(); override def write(obj: DateTime) = JsString(parserISO.print(obj)) override def read(json: JsValue) : DateTime = json match { case JsString(s) => parserISO.parseDateTime(s) case _ => throw new DeserializationException("Error info you want here ...") } }
Adapt it as you want if you do not want to use ISO formatting.