【问题标题】:Does Objectify support Joda-Time Interval class?Objectify 是否支持 Joda-Time Interval 类?
【发布时间】:2015-03-05 14:08:34
【问题描述】:

我们使用 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

【问题讨论】:

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


    【解决方案1】:

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

    DateTimeZone
    LocalDate
    LocalDateTime
    DateTime (via ReadableInstant)
    

    也许你可以从源代码中学习,编写自己的翻译器/适配器,例如看LocalDateTranslatorFactory的源代码,似乎没有那么难。但无论如何,您可能都必须注册自己的适配器。

    【讨论】:

    • 是的,我检查了源代码,我只是想确保我没有遗漏任何东西。
    猜你喜欢
    • 2013-08-28
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多