I'm developing a Play application, and I'm trying to use a Joda DateTime object into my case class.
package model
import org.joda.time.DateTime
import play.api.libs.json._
case class User(name: String, created: DateTime)
object User {
implicit val yourJodaDateReads = Reads.jodaDateReads("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
implicit val yourJodaDateWrites = Writes.jodaDateWrites("yyyy-MM-dd'T'HH:mm:ss.SSSZ'")
implicit val userFormat = Json.format[User]
def main(args: Array[String]) {
val value = Json.parse("{ \"name\" : \"hello\" , \"created\" : \"2015-07-16T20:32:04.046+02:00\" }")
println(Json.toJson(new User("user", new DateTime())))
println(Json.fromJson(value))
}
}
Based on this solution, I'm getting this error:
Error:(18, -1) Play 2 Compiler:
/activator-1.3.2/notifier-app/app/model/Test.scala:18: ambiguous implicit values:
both value yourJodaDateReads in object User of type => play.api.libs.json.Reads[org.joda.time.DateTime]
and value userFormat in object User of type => play.api.libs.json.OFormat[model.User]
I'm using Activator 1.3.2 and Play 2.3.8.
Could you please advice me ?
Thanks in advance.
update
I understand there is a conflict with the implicit value in play.api.libs.json.Reads
implicit val DefaultJodaDateReads = jodaDateReads("yyyy-MM-dd")
How can I resolve this issue ?