Objectify是否支持Joda-Time Interval课程?

时间:2015-03-05 14:08:34

标签: java google-app-engine jodatime objectify google-cloud-datastore

我们使用Objectify 5访问Google Cloud Datastore。我们有一个Joda-Time库中具有Interval类型属性的实体。当我们尝试保存这样的实体时,我们会得到以下错误。 Objectify似乎与Chronology及其子类存在问题。

com.googlecode.objectify.SaveException: Error saving MyEntity(null): Class 'class org.joda.time.chrono.ISOChronology' is not a registered @Subclass
    at com.googlecode.objectify.impl.EntityMetadata.save(EntityMetadata.java:95)
    at com.googlecode.objectify.impl.WriteEngine.save(WriteEngine.java:75)
    at com.googlecode.objectify.impl.SaverImpl.entities(SaverImpl.java:60)
    at com.googlecode.objectify.impl.SaverImpl.entity(SaverImpl.java:35)
...

我们在Objectify中注册了Joda-Time翻译以及我们的实体,如下所示。

...

// Joda-Time translators
JodaTimeTranslators.add(ObjectifyService.factory());

// persistent entities
ObjectifyService.register(MyEntity.class);

...

当我们使用DateTime代替Interval时,它的效果非常好。我们错过了什么吗? Objectify支持Joda-Time Interval开箱即用吗?

1 个答案:

答案 0 :(得分:3)

如果你看source code,显然不是。支持的类型是:

DateTimeZone
LocalDate
LocalDateTime
DateTime (via ReadableInstant)

也许你可以从源代码中学习并编写自己的翻译器/适配器,例如参见LocalDateTranslatorFactory的源代码。它似乎并不那么困难。但是你可能还是要注册自己的适配器。

相关问题