I have read this question (and the other ones on SO), but I still don't manage to convert a JsValue
to a case class with a Joda DateTime.
Here is the JSON I have:
val json = Json.parse(
"""
{
"message": "Bla bla bla",
"updated_time": "2016-09-17T12:48:12+0000"
}
"""
)
And the corresponding case class is:
import org.joda.time.DateTime
final case class FacebookPost(message: String, updated_time: DateTime)
I also added this implicit DateTime reader (I tried some other as well):
implicit val readsJodaLocalDateTime = Reads[DateTime](js =>
js.validate[String].map[DateTime](dtString => new DateTime(dtString)))
But when I try to convert my json to the corresponding case class (json.as[FacebookPost]
), I get this error:
play.api.libs.json.JsResultException: `JsResultException(errors:List((/updated_time,List(ValidationError(List(error.expected.jodadate.format),WrappedArray(yyyy-MM-dd))))))`
What am I doing wrong?