[英]Does Objectify support Joda-Time Interval class?
我們使用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
?
如果您查看源代碼 ,顯然不會。 支持的類型有:
DateTimeZone
LocalDate
LocalDateTime
DateTime (via ReadableInstant)
也許您可以從源代碼中學習並編寫自己的轉換器/適配器,例如,參見LocalDateTranslatorFactory的源代碼,這似乎並不困難。 但是無論如何,您可能必須注冊自己的適配器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.