Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
objectify.LoadException:java.time.LocalDateTime必须具有无参数构造函数_Java_Google App Engine_Java 8_Google Cloud Datastore_Objectify - Fatal编程技术网

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

objectify.LoadException:java.time.LocalDateTime必须具有无参数构造函数,java,google-app-engine,java-8,google-cloud-datastore,objectify,Java,Google App Engine,Java 8,Google Cloud Datastore,Objectify,我正在使用Java8LocalDateTime类在数据存储中持久化日期。 日期为此格式2017-07-24T01:00:00.000作为嵌入实体保留 private LocalDateTime matchDateTime; 持久化流程是正常的。但当我加载实体时,会抛出异常 com.googlecode.objectify.LoadException: Error loading : java.time.LocalDateTime must have a no-arg constructor

我正在使用Java8
LocalDateTime
类在数据存储中持久化日期。 日期为此格式
2017-07-24T01:00:00.000
作为嵌入实体保留

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]

但它仍然不能锻炼身体。有什么猜测吗?

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

在Objectify源代码中查找包
com.googlecode.Objectify.impl.translate.opt.joda
。它包含允许Objectify使用joda时间对象的翻译器;在注册实体类之前,请使用
ObjectifyFactory
注册这些对象。它们的工作原理应该是显而易见的;您只需要能够在
LocalDateTime
之间进行转换,并将其存储在数据存储中

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

           <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;