GrailsのJodaTimeプラグインの使用に問題があります。プラグインは出力用のJSONに正しく変換されているようですが、同じJSONオブジェクトが返送されたときに出力された日付形式を入力として再度受け入れることができないようです。GrailsがJSONから日時をアンマーシャリングしてjodaに戻すことができませんDateTime
これは私が得るエラーです:ここでは
Field error in object 'server.Session' on field 'lastUpdated': rejected value [2011-12-19T14:15:03-06:00]; codes [typeMismatch.server.Session.lastUpdated,typeMismatch.lastUpdated,typeMismatch.org.joda.time.DateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [server.Session.lastUpdated,lastUpdated]; arguments []; default message [lastUpdated]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'org.joda.time.DateTime' for property 'lastUpdated'; nested exception is java.lang.IllegalArgumentException: Invalid format: "2011-12-19T14:15:03-06:00" is malformed at "11-12-19T14:15:03-06:00"]
Field error in object 'server.Session' on field 'dateCreated': rejected value [2011-12-19T14:15:03-06:00]; codes [typeMismatch.server.Session.dateCreated,typeMismatch.dateCreated,typeMismatch.org.joda.time.DateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [server.Session.dateCreated,dateCreated]; arguments []; default message [dateCreated]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'org.joda.time.DateTime' for property 'dateCreated'; nested exception is java.lang.IllegalArgumentException: Invalid format: "2011-12-19T14:15:03-06:00" is malformed at "11-12-19T14:15:03-06:00"] id=33 version=0>
は非常に基本的なドメインモデルです:
:package server
import org.joda.time.DateTime
class Session {
DateTime dateCreated
DateTime lastUpdated
String ip
static constraints = {
ip blank: false
}
}
そしてここではショーや更新方法(それぞれJSONを送受信)です
これを修正するために何をする必要があるのか、私が正しく動作しているかどうかはわかりませんが、Grailsの新機能です。現実には、問題を引き起こしている2つの日付フィールドはGORMによって内部的に100%扱われなければならず、コントローラはそれらを完全に無視しますが、ドメインモデルが取得されると更新する必要のある他の日付フィールドがあります
自動JSONアンマーシャリングでjoda時間のDateTimeオブジェクトに正しく変換する方法を教えてください。
注:これは現在、クライアント/サーバーアプリケーションの概念実証です。