objectify.LoadException:java.time.LocalDateTime 必须有一个无参数构造函数

弱者

我正在使用 Java 8LocalDateTime类在数据存储中保留日期。日期是这种格式2017-07-24T01:00:00.000作为 EmbeddedEntity 持久化。

private LocalDateTime matchDateTime;

持久化流没问题。但是当我加载实体时抛出异常。

com.googlecode.objectify.LoadException: Error loading : java.time.LocalDateTime must have a no-arg constructor
    at com.googlecode.objectify.impl.EntityMetadata.load(EntityMetadata.java:78) ~[objectify-5.1.21.jar:na]
    at com.googlecode.objectify.impl.LoadEngine.load(LoadEngine.java:185) ~[objectify-5.1.21.jar:na]

Caused by: java.lang.IllegalStateException: java.time.LocalDateTime must have a no-arg constructor
    at com.googlecode.objectify.impl.TypeUtils.getNoArgConstructor(TypeUtils.java:47) ~[objectify-5.1.21.jar:na]
    at com.googlecode.objectify.ObjectifyFactory.construct(ObjectifyFactory.java:69) ~[objectify-5.1.21.jar:na]

Caused by: java.lang.NoSuchMethodException: java.time.LocalDateTime.<init>()
    at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_131]
    at java.lang.Class.getDeclaredConstructor(Class.java:2178) ~[na:1.8.0_131]

我该如何解决?

我研究并添加到我的 pom.xml 文件中。

           <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-parameter-names</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jdk8</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.8.9</version>
        </dependency>

将日期属性标记为

@JsonSerialize(using = ToStringSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime matchDateTime;

但它仍然没有锻炼。有什么猜测吗?

简笔画

当前版本的 Objectify 没有对 J8 数据类型的内置支持。但是,您可以非常轻松地在您的应用程序中添加支持。

查看包的 Objectify 源代码com.googlecode.objectify.impl.translate.opt.joda它包含允许 Objectify 使用 joda 时间对象的转换器;ObjectifyFactory在注册实体类之前,您可以使用 注册这些它们的工作方式应该很明显;您只需要能够在LocalDateTime您希望将其存储在数据存储中的方式和方式之间进行转换

一点警告:不要试图转换LocalDateTimejava.util.Date,它代表一个瞬间。LocalDateTime没有 TZ,因此不是瞬间。最好将其表示为 ISO 8601 字符串。看看ReadablePartialTranslatorFactory...虽然反射对于您的用例来说可能是不必要的。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

错误:实体和POJO必须有一个可用的公共构造 - Java的

Java动画-每帧必须有一个持续时间

最好的方法克隆java.time.LocalDateTime

如何解决“查询中的每个绑定变量必须有一个匹配方法的参数”,在Android的Java错误?

参数值[100]与预期的类型[java.time.LocalDateTime(n / a)]不匹配

如何使Spring Data Elasticsearch与java.time.LocalDateTime一起使用以获取日期

转换java.sql.date到java.time.LocalDateTime

适用于java.time.LocalDateTime的DynamoDBMapper

LocalDateTime.parse处的java.time.format.DateTimeParseException

参数类型的隐式 ParameterBinderFactory[org.joda.time.LocalDateTime]

如何使用模式格式化java.time.LocalDateTime和java.time.LocalDate?

JFreeChart:使用 java.time.LocalDate 或 java.time.LocalDateTime 创建图表

函数必须有一个明确的参数列表

JAVA FXCollections LoadException类不是有效的类型

java.lang.ClassCastException: java.util.LinkedHashMap 不能转换为 java.time.LocalDateTime

转换LocalDateTime到LocalDateTime在Java特定区

Java从LocalDateTime Bar减去LocalDateTime foo

IllegalArgumentException:无法将java.time.LocalDateTime字段设置为java.sql.Timestamp

Java 8 java.time:在Instant vs LocalDateTime中添加TemporalUnit

在java.time.LocalDateTime和java.util.Date之间进行转换

使用GSON将java.time.LocalDateTime(java 8)序列化为js Date的最佳实践

使用ZoneId.systemDefault()将java.util.Date转换为java.time.LocalDateTime

为什么在每个Fragment中都必须有一个公共的空构造函数?

客房持久性:实体和POJO必须有一个可用的构造函数

如何获取即将到来的特定时间的java.time.LocalDateTime对象?

无法从字符串反序列化类型为java.time.LocalDateTime的值

如何在p:calendar中使用java.time.ZonedDateTime / LocalDateTime

如何将文本输入转换为java.time.LocalDateTime?

字符串到LocalDateTime的转换:java.time.format.DateTimeParseException