Grails 4 仅对 Date 对象"Static Type Checking"错误



所以我是从Grails 3.3迁移过来的。X到4.0.13。当我尝试编译我的应用程序时,当我尝试使用任何日期属性的format方法时,我会得到编译错误。例如

class Event {
Date startDateTime
Date regDeadline
}

然后在GSON类中有这个

model {
Event event
}
json {
eventDate event.startDateTime.format("MM/dd/yyyy hh:mm a")
regDeadline event.regDeadline.format("MM/dd/yyyy hh:mm a")
}

得到以下编译错误

Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
raa_domain_grid__event_gson: 10: [Static type checking] - Cannot find matching method java.util.Date#format(java.lang.String). Please check if the declared type is correct and if the method exists.
@ line 10, column 15.
eventDate event.startDateTime.format("MM/dd/yyyy hh:mm a")
^
raa_domain_grid__event_gson: 11: [Static type checking] - Cannot find matching method java.util.Date#format(java.lang.String). Please check if the declared type is correct and if the method exists.
@ line 11, column 17.
regDeadline event.regDeadline.format("MM/dd/yyyy hh:mm a")

此操作以前没有问题。我怀疑这与Groovy升级到2.5.6有关,但我不知道是什么问题。这是发生在我的整个应用程序。我所有的类,有日期作为属性抛出这个错误,当我试图应用格式化给他们。以上只是一个简单的例子。

刚刚发现Date帮助器方法在Groovy 2.5中被删除并放入另一个库groovy-dateutil中。把这个添加到Gradle构建文件中,一切都按预期编译了。

相关内容

最新更新