Ich entwickle eine Play-Anwendung, und ich versuche, ein Joda DateTime-Objekt in meiner Fallklasse zu verwenden.Wie man Joda DateTime mit Play Json verwendet
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))
}
}
Basierend auf dieser solution, erhalte ich diese Fehlermeldung:
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]
Ich bin mit Activator 1.3.2 und 2.3.8 Wiedergabe.
Könnten Sie mich bitte beraten?
Vielen Dank im Voraus.
Update
Ich verstehe ein Konflikt mit dem impliziten Wert gibt es in play.api.libs.json.Reads
implicit val DefaultJodaDateReads = jodaDateReads("yyyy-MM-dd")
Wie kann ich dieses Problem beheben?
mögliche Duplikate von [Custom JodaTime Serializer mit JSON-Bibliothek von Play Framework?] (Http: // Stackoverflow.com/questions/18255504/custom-jodatime-serializer-using-play-frameworks-json-library) –
Bitte lesen Sie meinen Beitrag, anstatt eine schlechte Antwort zu beantworten. Ich habe diesen Link zitiert, weil mein Code auf diesem Thread basiert. – Guillaume